• 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

enroll_table three field fetch to payment form to create payment field in laravel 5.5

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

Combining a describing and one array with data

Laravel Nova, route not found

Laravel Excel::store file empty after stored

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

How to get array values using foreach in laravel

Change user role if checkout custom checkbox is checked in WooCommerce

PHPMyAdmin not working as intended at remote server. Error 500, $respond not found

How to add a custom field to all Woocommerce attribute terms using add_action

Jquery DataTables: Data not displaying in table via Ajax

Telegram bot doesn't answer

Target Laravelista is not instantiable

auth pages not getting css in laravel

Laravel multi auth - Authentication user provider [] is not defined

About Contact Privacy policy Terms and conditions