• 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

Symfony process run throws exception - executing on command line works

Why rand() every time I refresh the page?

Can't call javascript alert alertify library from PHP

OctoberCMS / Anonymous Global Scope

How can i call a function that executes an fpdf based on the choice of a form selector?

Add customer email and phone in "Order" column to admin orders list on Woocommerce

WooCommerce - unset "<product> removed notice…" on cart page

PHP error: "The zip extension and unzip command are both missing, skipping."

Redis Command To Sort Keys

Yii2 select2 database exception number of bound variables does not match number of tokens

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

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

Edit XML in HTML form and submit to self

Using array_intersect on a multi-dimensional array

Laravel 5 controller sending JSON integer as string

About Contact Privacy policy Terms and conditions