• 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

Show date difference as "20" instead of "20 years ago"

Not able to access model in the controller mautic

Laravel lang slug in url

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Laravel get user data with profile

No definition found for function in vendor vscode

Make certain characters of a word from string bold

Create tags in laravel post publishing

Connecting an HTML webpage to a SQL Server

Laravel views are showing from cache on one server but works fine on other server

Laravel Nova, route not found

Adding multiple items to WooCommerce cart at once

Get data from accuweather api url

How to get Laravel's CSRF Token from Another Website?

How to load Codeigniter 4 lang file into an array variable

About Contact Privacy policy Terms and conditions