• 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

Failing validation doesn't stop code execution in livewire component

Split comma separated value from table column into rows using mysql?

(Laravel) How to delete multiple models including optional relationships?

VB.NET WebRequest with PHP POST

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

jwt decode throws Invalid argument supplied for foreach() on php-jwt and codeignitor 4

Match csv filenames to table names and import

How to execute sql code based on fetch array

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

PHP if in_array() how to get the key as well?

Match single unknown parameter php (Morse-code Regex)

Laravel set default language not working

Add restriction to WooCommerce coupons by allowed user ID

Lexik JWT authentication problem "Invalid credentials"

Alert message after submitting form in PHP

About Contact Privacy policy Terms and conditions