• 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

PHP web3 ERC20 token function call

How to set dynamic `home` and `siteurl` in WordPress?

WHM Enabling mod_rewrite

Magento Installation SQLSTATE[HY000] [2002] No such file or directory error

PHP -> Next nearest date defined by array of days in week

How to implement placeholder in a php file for moodle plugin?

Why rand() every time I refresh the page?

PHPUnit (Phar) Fatal Error Only When Test Fails

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

Mysqli multi query error

Twig - How to check if variable is a number / integer

Display Link Title Instead of URL in XSL

Wordpress wpdb->delete issue

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

How to install PHP composer inside a docker container

About Contact Privacy policy Terms and conditions