• 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 sanctum Route [login] not defined

Substitute integers and dots with regex [duplicate]

disable two buttons after clicking another button

Sliders in Laravel

PHP error: "The zip extension and unzip command are both missing, skipping."

How do I upload a laravel project on cPanel shared hosting?

PHP-Sort array based on another array?

api response laravel doesn't show

PHP cURL (SSL certificate problem: self signed certificate in certificate chain)

CodeIgniter 3 is generating a session file on each request, why?

MySQL/PHP - Web Based Game -User specific inventory table or 1 giant table? Another option?

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

How to reset Laravel AuthManager/guards in between API calls in tests?

Laravel set default language not working

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

About Contact Privacy policy Terms and conditions