• 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 Jetsream Profile page not loading on fresh install

Laravel Collections. Is there some kind of assertStructure method?

wordpress : How to specify the cause "This site can’t be reached"

How can I make this nested location configuration use the correct path to call a php program?

How to change 'users' auth table and use another instead Laravel

Check if a string contain multiple specific words

Make certain characters of a word from string bold

how to make my own auto increment in php?

Laravel relationship belongsToMany with composite primary keys

Laravel 5 controller sending JSON integer as string

PHP: Convert any string to UTF-8 without knowing the original character set, or at least try

Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?

How to set a domain name with php artisan serve

Add a custom text for a particular product on specific email notification in Woocommerce

WordPress + Nginx on non-standard port behind AWS ELB results in broken links

About Contact Privacy policy Terms and conditions