• 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

PHP's array_map including keys

How to add automatically collapse/expand in content wordpress (single.php)?

Select option menu read from database and use it's values

Boolean assignment operators in PHP

Return new collection without modifying original collection

How to make a array inside array?

Populate Dynamic Dropdowns List in Codeigniter

Multiple order by in WooCommerce

PHP sort array of objects by two properties

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)

How to load Codeigniter 4 lang file into an array variable

Toggle between a textbox and a select using PHP

How to insert Google Adsense Code in PHP script?

Getting values for an enum?

Symfony there are no commands defined in the "make" namespace

About Contact Privacy policy Terms and conditions