• 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

Put content of wordpress page inside div

With doctrine ODM, can I embed many subdocuments in a main document?

Check if user online laravel

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

how to make my own auto increment in php?

Creating live search with AJAX and CodeIgniter

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel

Cache clear probem in Larave

php curl requesting twice

Laravel Blade checkbox not checked

Laravel display validation error

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

PHP header location absolute URL

How to set a domain name with php artisan serve

PHP if in_array() how to get the key as well?

About Contact Privacy policy Terms and conditions