• 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

Spam Filter in Contact Form

wp_remote_get() not passing authentication

Remove categories with all childs derived from parent category

Laravel csrf token mismatch for ajax POST Request

Required field only if another field has a value, must be empty otherwise

Why the name of trucks are same in 2nd and 3rd record of company data retrieval?

Issue with laravel eloquent model property

How to map the two arrays with a duplicate value?

Hi, I am making a contact form thingy, and my php isn't working any reason why?

Display Link Title Instead of URL in XSL

Batch request Google Calendar php API

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

Lumen - Postgresql setup - Composer

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

SQLSTATE[HY000]: General error: 1 table posts has no column named *

About Contact Privacy policy Terms and conditions