• 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

How to KeyBy where multiple items have the same key

how to retrieve the first and last instance of a row in pdo dataset

Laravel eloquent update record without loading from database

Star and Half Star Rating in Laravel

Pass a select with mysqli_fetch_row to a table

Message: Set sys_temp_dir in your php.ini after installed composer

Log a user out of a website when they put their computer to sleep

Get latest Tweets - What API

Detect emoticons in string

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

How to keep value of selected value after form submission?

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

Why does array_map() with null as callback create an "array of arrays"?

VB.NET WebRequest with PHP POST

Laravel You requested 1 items, but there are only 0 items available

About Contact Privacy policy Terms and conditions