• 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

PHP mail function is sending blank message body

PHP Imap , php 7.4.3 on mac osx catalina

PHP DOTENV unable to load env vars

How to install php_imagick on wamp64

sort() not affecting original array while inside foreach loop

How to disable only_full_group_by option in Laravel

Not able to access model in the controller mautic

send email using gmail-api and google-api-php-client

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

woocommerce_wp_select options array from product attribute terms

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

Laravel Livewire: jQuery not working in child component loaded via @if statement

Pass a select with mysqli_fetch_row to a table

PHP: remove filename from path

laravel controller function parameters

About Contact Privacy policy Terms and conditions