• 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

Using array_intersect on a multi-dimensional array

Laravel get user data with profile

PHPExcel export HTML table to xlsx

How to find phpcs current default standard

Creating Combinations of Elements

How to put php code inside opening and closing shortcodes

PHP my timezone is no setting up in PHP.ini File in xampp

PHPExcel How to set conditional formatting to change cell background color based on cells values

PHP if in_array() how to get the key as well?

laravel MVC execution flow

How to get values inside <![CDATA[values]] > using php DOM?

Is there a way to use Foundry Model for Authentification inside Functional Tests?

Image upload not working through ajax Laravel

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

Ajax GET request fails in laravel 8

About Contact Privacy policy Terms and conditions