• 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

How to Mock the Request Class in Laravel?

Alert message after submitting form in PHP

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

Lexik JWT authentication problem "Invalid credentials"

How to make a foreign key not using primary key

Render the content of default_filter.php in Joomla front-end

Laravel Factory not calling callback 'afterCreating'

Installing Composer - Internal Error

Star rating with half star support

PhpSpreadSheet: How to save Workbook sheets in individual CSV files

Target Laravelista is not instantiable

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

Hide specific products from unlogged users based in product category in WooCommerce

Having trouble with PDO queries (Notice: Undefined index)

shell errors running php exec

About Contact Privacy policy Terms and conditions