• 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 connect to MSSQL Server with PHP from Ubuntu 18.04?

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

Move a child array to parent array and change parent/child name

How to insert Google Adsense Code in PHP script?

Laravel Get Days In Month From Month Number?

php curl_exec() Connection refused when retrieving a remote image

Problem with fetching data from database in Laravel

PDOException SQLSTATE[HY000] [2002] No such file or directory

Elastic Beanstalk with Laravel Envoy

How to write PHP in XSLT

PHP Fatal error: Class not found - PHPUnit

Laravel lang slug in url

Can't call javascript alert alertify library from PHP

Laravel views are showing from cache on one server but works fine on other server

PHP Sorting - getting 10, 11, 12 ... 1, 20, 2 rather than 1, 10, 11, 12 ... 2, 20

About Contact Privacy policy Terms and conditions