• 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

Laravel update hasMany relationship using saveMany

Laravel Get Days In Month From Month Number?

User pool client {id}does not exist

Query Optimization, changing the queries in the loop into a single processing query

Required field only if another field has a value, must be empty otherwise

Make Calculator - When Button clicked the No shows in Textbox.

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

Why does using salted hash on python and php give me different results?

Laravel Carbon throws error The format separator does not match

Laravel Livewire: jQuery not working in child component loaded via @if statement

laravel sanctum Route [login] not defined

php echo xml documents with header

api response laravel doesn't show

advanced custom fields wordpress custom class

could not find driver Debian SQL Server PHP

About Contact Privacy policy Terms and conditions