• 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

PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"

Fetch files from next cloud storage and display in Laravel website

Eloquent insert id with sequence next value

Get number of working days between two dates in PHP [duplicate]

PHP array, move keys and values to new array, but mix it up

How to make autocomplete work in foreach php loop? (vscode, intellisense)

XAMPP keeps showing Dashboard/Welcome Page instead of the Configuration Page

Get WooCommerce product variation attribute terms in admin products general box

Clear javascript source cache laravel 5.8

How can I easily switch between PHP versions on Mac OSX?

PHP Array split string and Integers

Any AWS EB Laravel route getting 404 Not Found nginx/1.16.1

401 Unauthorized only occurring on some pages in Laravel 8

Composer Script echo

The "client_reference_id" argument is not passed

About Contact Privacy policy Terms and conditions