• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How in Laravel run JavaScript code stored in php variable?

phplaravellaravel-livewire


PHP Snippet 1:

public $foo;

$this->dispatchBrowserEvent('custom-event', ['foo' => $this->foo]);

PHP Snippet 2:

<script>
    window.addEventListener('custom-event', event => {
          alert('here value foo: ' + event.detail.foo);
          console.log(event.detail.foo);
    })
</script>

PHP Snippet 3:

<script>
    document.addEventListener('custom-event', () => {
        {!! json_encode($script) !!}
    })
</script>

Related Snippets

Get image type from base64 encoded src string

how to upload binary image to sql server using php laravel

Laravel Gates using model and returns "Using $this when not in object context" Line 28 of AzureUser model

PHP using str_starts_with for array to exclude same as with wildcard

Laravel Route issues with Route order in web.php

Laravel views are showing from cache on one server but works fine on other server

PHP - installing Xdebug on Mac with XAMPP (Unix File)

phpunit - mockbuilder - set mock object internal property

How to access a var with "-" in PHP [duplicate]

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Detect emoticons in string

If action is on a different page do I use fwrite function

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

TesseractOCR not working for Laravel

Override default Auth routes in Laravel 7

About Contact Privacy policy Terms and conditions