• 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

Laravel multi auth - Authentication user provider [] is not defined

possible options to create pdf file using html elements to generate invoice in php and codeigniter

Utf8 encoding issue with Laravel

Using array_intersect on a multi-dimensional array

Symfony redirect if already loggedin from login page

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

Class AppHttpControllersUserController Does Not Exist

How to make dot match newline characters using regular expressions

PHPSpreadsheet - How Do I Use Auto Migration Tool

How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?

Ajax GET request fails in laravel 8

Transfer data between JavaScript and PHP through JSON

How do I call Validator from a namespace with an already existing Validator class

Transpose and flatten multiple rows of array data [duplicate]

Having issue with matching rows in the database using PDO

About Contact Privacy policy Terms and conditions