• 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

Input and output values for php into the browser?

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

How to edit Records using CodeIgniter

SilverStripe unable to populate multiple member Childs

WAMP Virtual Host not working

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

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

Results page in other window

Laravel - How to properly generate unique slugs from article titles?

Correctly determine if date string is a valid date in that format

WordPress Security Standards want me to escape my html, but how to do it correctly?

How can I convert from a{a{} b{}} to a[a[],b[]] using php preg_match?

how to identify the web server name of remote host

Laravel 5 issue with wherePivot

About Contact Privacy policy Terms and conditions