• 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

woocommerce get_order_report_data to show order_item_id

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

php mysql + create a friend request system

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

Laravel UUID generation

PHP -> Next nearest date defined by array of days in week

Laravel relationship belongsToMany with composite primary keys

Cannot pass null argument when using type hinting

How to get total pages of PDF with FPDF?

How to create a cookie to store the timestamp of when a page is first loaded with php

Target class controller does not exist - Laravel 8

Store multiple fields in JSON column (Nova CMS)

Access denied for user 'homestead'@'localhost' (using password: YES)

How to install LDAP in Docker php-fpm alpine

Check for PDO Results, If None Display Message, If Yes then Loop Through

About Contact Privacy policy Terms and conditions