• 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

How can I create a Download Page with post php method?

phpunit - testing is painfully slow

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

PHP sort array of objects by two properties

WAMP Virtual Host not working

Limit login attempts in Laravel 5.7

Create tags in laravel post publishing

Jquery DataTables: Data not displaying in table via Ajax

php curl requesting twice

How to convert time from one timezone to another in PHP

Laravel 5 session not persisting after user is logged in

Exact alternate to mcrypt_encrypt in PHP 7.2

Show only featured products in Woocommerce shop page

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

WHERE IN array binding in DB::raw laravel 5.4

About Contact Privacy policy Terms and conditions