• 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

google content api for shopping

Laravel Delete and Update

Adding one microsecond to Datetime object in PHP

PHP: set a (deep) array key from an array [closed]

Laravel websockets AWS EC2 - Connection failed

Laravel PHP: multiple project run at the same time [closed]

PHP: How to solve ob_start() in combination imagepng() issue?

Combine array with same value and add other [duplicate]

MySQL default time format UTC or GMT?

Composer Curl error 60: SSL certificate problem: unable to get local issuer certificate

PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: no such host known

Get image type from base64 encoded src string

Put content of wordpress page inside div

CodeIgniter extend CI_URI undefined method

How to disable widget block editor of WordPress?

About Contact Privacy policy Terms and conditions