• 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

CodeIgniter 3 is generating a session file on each request, why?

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

PHP Deprecated issue when running artisan command

Get latest Tweets - What API

How to find the date a user created their Google account

How to add a sidebar to Woocommerce Shop Page?

How to properly set "0000-00-00 00:00:00" as a DateTime in PHP

PHP 8.1: strftime() is deprecated

How to to send mail using gmail in Laravel?

Wordpress how to get the post thumbnail inside a figure tag

How to install ZeroMQ for PHP on an Alpine Linux container?

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

How to make autocomplete work in foreach php loop? (vscode, intellisense)

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

How to loop sql table data inside a html table

About Contact Privacy policy Terms and conditions