• 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

Android Volley getParams() method not getting called for JsonObjectRequest

Natural ORDER in Laravel Eloquent ORM

woocommerce get_order_report_data to show order_item_id

Laravel Factory not calling callback 'afterCreating'

(Cache::lock()) -> get() -- Under what conditions does it return false?

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

Get data from accuweather api url

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

Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path: ) in Unknown on line 0

Adding reCAPTCHA v2 into my PHP file

Xdebug in Laravel is not working with VSCode

Display the WooCommerce product price inside a custom function

php retrieve specific data onclick from database in a list format

ConstraintViolationListInterface to Exception in Symfony

Calculating Median of an array in PHP

About Contact Privacy policy Terms and conditions