• 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

Clear javascript source cache laravel 5.8

Call to a member function givePermissionTo() on null

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

Cache clear probem in Larave

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

Detect a fetch request in PHP

PHP array stringify

Laravel passport auth token not working after moving to different server

How to convert time from one timezone to another in PHP

Adding the custom page with add_menu_page function on Wordpress

How to redirect to another page after n seconds in wordpress without using javascript?

Woocommerce product attributes with hierarchy like categories

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

Can't exclude directories from .htaccess mobile redirect?

How to validate Envato Purchase Code in PHP

About Contact Privacy policy Terms and conditions