• 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

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Laravel: Why is my variable not being set while it's in the construct function of the controller?

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

How to loop a tree array with unknown depth and get array blocks?

How to disable widget block editor of WordPress?

Login if user is active using Laravel Breeze

Execute only one time and then wait set period of time before executing again

Laravel: Create morphs() relationship nullable

What is the difference between client-side and server-side programming?

Split a string array into pieces

stay with the last 15 elements of an array [duplicate]

How can I stop a symfony process which is listening on http://127.0.0.1:8000

merging two arrays with specified index

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

Calculating Median of an array in PHP

About Contact Privacy policy Terms and conditions