• 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

Laravel Database Strict Mode

xdebug 3 not working in ubuntu 20.04 with docker

What is PHP's equivalent of JavaScript's "array.every()"?

How to install php_imagick on wamp64

How to KeyBy where multiple items have the same key

PHPExcel file download using AJAX call

json_encode turns array into an object

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

Create tags in laravel post publishing

Converting array to string and then back in PHP

Log file is not being written in Laravel 5.5

Required field only if another field has a value, must be empty otherwise

Select option menu read from database and use it's values

WooCommerce Subscriptions: Remove role on cancelled subscription

About Contact Privacy policy Terms and conditions