• 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

mysql slow on updates for a well optimized query

Creating command to backup MySql database in Laravel

Destroy session upon refresh

Distribute array row data to make multiple new rows

How to write PHP in XSLT

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

MySQL order by field in Eloquent

Laravel 8 factory state afterCreating

insert multiple rows in a saveall in cakephp

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

Remove product downloads section in woocommerce email notifications

array_key_exists(): The first argument should be either a string or an integer

Can we define variables in `.tpl` files?

Get all WooCommerce products within own plugin

Form repeater send wrong data with last element in Laravel

About Contact Privacy policy Terms and conditions