• 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 edit Records using CodeIgniter

Center point of multiple gps coordinates with php

Make Shipping Method fields Mandatory on Woocommerce checkout page

PHP: convert all UTF-8 characters to HTML entities

Add bold text and line break into Laravel Notification Email

Laravel Jetsream Profile page not loading on fresh install

How to Mock the Request Class in Laravel?

Cant seem to get the Pagination to work on my WooCommerce REST API application?

Log file is not being written in Laravel 5.5

How to get monthly wise data in laravel

How to separate letters and digits from a string in php

JSON Render Issue in Date Object Laravel and PHP 7.4

How can I make a full text index of the column?

Target class controller does not exist - Laravel 8

Laravel Command Schedule Not Working Properly

About Contact Privacy policy Terms and conditions