• 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

Merge key and value of array index [duplicate]

Hide specific products from unlogged users based in product category in WooCommerce

laravel and phpunit: could not find driver (SQL: PRAGMA foreign_keys = ON;)

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

Laravel Passport - Not able to get token string in response?

loop through an anchor id

ldap is missing from system when installing adldap2 in laravel

Log file is not being written in Laravel 5.5

Insert And Retrieve Data in MySQL with $.post Noob Question

laravel MVC execution flow

*** 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

image source not readable

Xdebug 3 not showing in phpinfo on m1 Monterey

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

Nginx disallowing execution of PHP in uploads directory with Magento

About Contact Privacy policy Terms and conditions