• 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

Trying to iterate over a mongodb cursor twice - failing

Laravel Factory not calling callback 'afterCreating'

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

file_put_content...fail to open stream:Permission denied in Laravel 5

PHP Slim Framework request using withAttribute error

Laravel 8: Array to string conversion while calling route:list

Parameter is not sent to Laravel route in Ajax

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

Can I use a WooCommerce function without any WooCommerce page?

How to pass data to all views in Laravel 5?

How do I enable error reporting in Laravel?

Display specific shipping method if woocommerce product has specific acf field value

php 7 php.ini upload_max_filesize not working

How to validate Envato Purchase Code in PHP

Get keys from associative array [duplicate]

About Contact Privacy policy Terms and conditions