• 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

Star and Half Star Rating in Laravel

How to install LDAP in Docker php-fpm alpine

Hide specific products from unlogged users based in product category in WooCommerce

Laravel implode array items to new lines

401 Unauthorized only occurring on some pages in Laravel 8

How to get total pages of PDF with FPDF?

PHP web3 ERC20 token function call

Laravel UUID generation

How to change 'users' auth table and use another instead Laravel

Transpose and flatten multiple rows of array data [duplicate]

renameColumn migration fails for existing column with columns does not exist error

wp_remote_get() not passing authentication

Using spatie/media-library, how to rename a collection of uploaded files?

Laravel 8 Multiple Relationships for Factory

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

About Contact Privacy policy Terms and conditions