• 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

Issue saving card for customer

Laravel php artisan serve to mimic HTTPS

How to get multiple values with same key from an array PHP

shell errors running php exec

Laravel set default language not working

Laravel 8: Array to string conversion while calling route:list

How to get the ID of the link in another page in php

PHP: How to raise number to (tiny) fractional exponent?

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

401 Unauthorized only occurring on some pages in Laravel 8

How to downgrade or install a specific version of Composer?

Display a success custom notice after Placing an Order in WooCommerce

Laravel: Create morphs() relationship nullable

how to identify the web server name of remote host

Execute only one time and then wait set period of time before executing again

About Contact Privacy policy Terms and conditions