• 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

If action is on a different page do I use fwrite function

Calculating Median of an array in PHP

Respond with status code 401 on authentication failure using Laravel and Passport?

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Laravel Carbon throws error The format separator does not match

Composer Script echo

Google API Heatmap Layer exception, why?

Laravel Collections. Is there some kind of assertStructure method?

generating a random code in php?

Laravel-fopen: failed to open stream: Permission denied

Doctrine ORM: Excluding Records Based on Values of Nested Relationships

error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

Convert every two values of an associative array into key-value pairs

file_put_content...fail to open stream:Permission denied in Laravel 5

Show only featured products in Woocommerce shop page

About Contact Privacy policy Terms and conditions