• 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

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

Adding Multiple Custom Post Types in Wordpress

How to increase the PHP upload limits [duplicate]

find in set in laravel ? example

What will the best solution for this multiple optional filter?

Converting IPv6 to IPv4 address in PHP

Why does codeigniter & Linux server throws unserialize() session data error when user tries to login

Limit of log line written to Apache Errorlog from mod php error_log

PHP my timezone is no setting up in PHP.ini File in xampp

How to fix bootstrap multiselect search data using ajax

Xdebug can't connect back to Docker host

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Can I use a WooCommerce function without any WooCommerce page?

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

About Contact Privacy policy Terms and conditions