• 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

Store / Website Column in Magento 2 Admin Grid - Custom Module

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

Prestashop cUrl Login

php curl requesting twice

Multiple order by in WooCommerce

CSV to PHP class properties

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

Add custom text under order details on WooCommerce My account view order pages

How to implement placeholder in a php file for moodle plugin?

How to get total pages of PDF with FPDF?

Symfony there are no commands defined in the "make" namespace

Image upload not working through ajax Laravel

How to edit Records using CodeIgniter

Laravel Schedule not sending email

oauth-private.key does not exist or is not readable

About Contact Privacy policy Terms and conditions