• 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

Composer Script echo

PHP - Check if string contains words longer than 4 characters, then include "+ *", and for those shorter than 4 characters include only "*"

Laravel Delete and Update

Laravel Excel::store file empty after stored

Combine multiple columns into an array as one of the key in a results set

GuzzleHttp Hangs When Using Localhost

How to properly start Laravel 8 with Bootstrap & authentication

virtctl works when executed via command line but not from php exec()

image source not readable

Add 2 Webcam in one page with WebcamJS

How to check user Permissions using Custom Middleware in Laravel

Cant seem to get the Pagination to work on my WooCommerce REST API application?

Laravel relationship belongsToMany with composite primary keys

401 Unauthorized only occurring on some pages in Laravel 8

Combine array with same value and add other [duplicate]

About Contact Privacy policy Terms and conditions