• 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

*** ERROR *** The PHP configuration loaded file is: c:/wamp64/bin/php/php8.1.0/php.ini - should be: c:/wamp64/bin/apache/apache2.4.53.1/bin/php.ini

Store multiple fields in JSON column (Nova CMS)

How to run a shell as root from php (apache)

Symfony process run throws exception - executing on command line works

How to add a sidebar to Woocommerce Shop Page?

How to install LDAP in Docker php-fpm alpine

Unsure why I am getting: Number of variables doesn't match number of parameters in prepared statement

How to use React Router with Laravel?

Laravel Collections. Is there some kind of assertStructure method?

Custom add to cart button URL for specific product in WooCommerce?

enable Apache http Authorization header

What is PHP's equivalent of JavaScript's "array.every()"?

Can I use a WooCommerce function without any WooCommerce page?

Laravel Collections. Is there some kind of assertStructure method?

Laravel views are showing from cache on one server but works fine on other server

About Contact Privacy policy Terms and conditions