• 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

WordPress Subquery returns more than 1 row on SELECT

php curl requesting twice

PHP function Not Working As Expected From functions.php Include File

PHP Print to Network Printer

How to make Canonicals with PHP

httpd.conf on Windows: can't locate API model structure `php8_module`

How to get AJAX to post on second page?

Composer Warning: openssl extension is missing. How to enable in WAMP

How can i hide dt if dd got empty value

Laravel lang slug in url

Respond with status code 401 on authentication failure using Laravel and Passport?

Make survey at laravel 5.4 and MySQL

IlluminateDatabaseQueryException could not find driver [duplicate]

Creating command to backup MySql database in Laravel

Adding reCAPTCHA v2 into my PHP file

About Contact Privacy policy Terms and conditions