• 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 make Canonicals with PHP

XAMPP keeps showing Dashboard/Welcome Page instead of the Configuration Page

How to Mock the Request Class in Laravel?

Hi, I am making a contact form thingy, and my php isn't working any reason why?

Laravel 8: Array to string conversion while calling route:list

CSV to PHP class properties

PHP: remove filename from path

Laravel 5.1 how to use {{ old('') }} helper on blade file for radio inputs

Loading data from MySQL and populating dropdown select with jQuery Mobile, PHP

Reload parent page after submit in iframe

How to get unique slug to same post-title for other time too?

How to get unique slug to same post-title for other time too?

Laravel 5.2: Unable to locate factory with name [default]

Laravel Route issues with Route order in web.php

php script to delete files older than 24 hrs, deletes all files

About Contact Privacy policy Terms and conditions