• 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

No result using makeStyles Material UI in react 18

OctoberCMS / Anonymous Global Scope

How to install ZeroMQ for PHP on an Alpine Linux container?

PHP each() function replacement

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

How to execute sql code based on fetch array

Fetch files from next cloud storage and display in Laravel website

Laravel: Why is my variable not being set while it's in the construct function of the controller?

How to run or debug php on Visual Studio Code (VSCode)

How to fix 'Data has already been sent to output, unable to output PDF file' in MPDF

Cut an arabic string

Reorder attribute dropdown terms in Woocommerce single variable products

How to put php code inside opening and closing shortcodes

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

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

About Contact Privacy policy Terms and conditions