• 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 mail function is sending blank message body

How to send image,audio or video through the WhatsApp API - PHP

How to insert data from multiple select dropdown values into database?

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Unable to uninstall brew php from homebrew

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

Laravel lang slug in url

Laravel MSSQL Server Connection not working

LARAVEL: How to fetch id dynamically in a query builder?

Creating command to backup MySql database in Laravel

How do I do HTTP basic authentication using Guzzle?

How to install LDAP in Docker php-fpm alpine

Symfony Mercure "Failed to send an update"

Laravel post contact form giving me error 419

How to KeyBy where multiple items have the same key

About Contact Privacy policy Terms and conditions