• 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

Laravel PHP: multiple project run at the same time [closed]

Laravel Database Strict Mode

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

(Laravel) How to delete multiple models including optional relationships?

Google Gmail API - How to login programatically?

PHP Print to Network Printer

PHP header location absolute URL

How to send upload image through email

How to run or debug php on Visual Studio Code (VSCode)

How to read laravel_session cookies saved in cookie memory of browser in client side?

I want to store data in new index as per my key in php [duplicate]

PHPExcel_IOFactory::createWriter causes wrong behaviour

Doctrine 2 mapping referencing unique key

PHP: set a (deep) array key from an array [closed]

Match single unknown parameter php (Morse-code Regex)

About Contact Privacy policy Terms and conditions