• 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

PHP array sort and remove duplicates by two field values

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

How can i hide dt if dd got empty value

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

Laravel 5 session not persisting after user is logged in

Clear javascript source cache laravel 5.8

How to render html from a @foreach loop in a textarea

Laravel query builder binding parameters more than once

Get Header Authorization value of a login api (sent with username and password in json body) using php curl

image source not readable

IlluminateDatabaseQueryException could not find driver [duplicate]

Google Gmail API - How to login programatically?

phpunit - mockbuilder - set mock object internal property

JQuery content editable div and text box on submit not sending POST

About Contact Privacy policy Terms and conditions