• 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

MongoDB Duplicate Documents even after adding unique key

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

Show only featured products in Woocommerce shop page

Form repeater send wrong data with last element in Laravel

I want a way to give path to my files which are outside of public folder in laravel

Additional price based on cart item count in WooCommerce

display WooCommerce “Add to cart” button with short-code [add_to_cart ] dynamically

if statement inside concatenation

How can i update or reset my password without entering email field in laravel-8?

how to redirect the user back to desired URL after login page in PHP?

WooCommerce: Add/display Product or Variation custom field everywhere

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

Show date difference as "20" instead of "20 years ago"

Wordpress add responsive srcset header image to theme

Cache clear probem in Larave

About Contact Privacy policy Terms and conditions