• 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

WordPress Subquery returns more than 1 row on SELECT

laravel and phpunit: could not find driver (SQL: PRAGMA foreign_keys = ON;)

How can I make good efficent AJAX live forms with just jQuery and

Lexik JWT authentication problem "Invalid credentials"

Laravel 5.1 Unknown database type enum requested

php - add comma thousands separator but remove trailing zeros

Filter WooCommerce related products by Polylang language

Why rand() every time I refresh the page?

How to debug in WooCommerce 3+

args[max_input] woocommerce if statement confused

Add bold text and line break into Laravel Notification Email

Laravel You requested 1 items, but there are only 0 items available

How to add class name to an existing tag in php

woocommerce_wp_select options array from product attribute terms

Create tags in laravel post publishing

About Contact Privacy policy Terms and conditions