• 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 Security Standards want me to escape my html, but how to do it correctly?

Edit product hook WooCommerce

args[max_input] woocommerce if statement confused

Symfony Make:Migration : The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue

How to create a scheduler application in php

Explain how this array transposing and flattening function works

401 Unauthorized only occurring on some pages in Laravel 8

Add a custom text for a particular product on specific email notification in Woocommerce

Set quantity minimum, maximum and step at product level in Woocommerce

Spam Filter in Contact Form

Display a product custom field only in WooCommerce Admin single orders

Apply session id from request header

How to disable widget block editor of WordPress?

Send POST data via raw JSON with Postman

Eloquent insert id with sequence next value

About Contact Privacy policy Terms and conditions