• 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

Passing a boolean value from checkbox in Laravel form

How to get the survey List from surveygizmo API in the Postman?(Trial Version)

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given [duplicate]

GRPC installed successfully on ubuntu but php is looking for it in another folder

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

Get orders by date and status woocommerce

How to delete old images from public folder on update using Laravel

Unable to guess the mime type as no guessers are available Laravel 5.2

api response laravel doesn't show

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

Form repeater send wrong data with last element in Laravel

Wordpress how to get the post thumbnail inside a figure tag

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

About Contact Privacy policy Terms and conditions