• 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

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

Cache clear probem in Larave

Mysqli multi query error

Sum array values of a column within each column of an array with 3 levels

Dropzone: Submit both form data and dropzone at once

Convert date and time to Jalali in Laravel

Facebook API, get page post link (PHP)

Select option menu read from database and use it's values

How to retrieve Active Directory group policy maximum password age using LDAP

Filter WooCommerce related products by Polylang language

Failing validation doesn't stop code execution in livewire component

How do I pass the dynamic output of a php variable or php function to a CSS variable?

Adding reCAPTCHA v2 into my PHP file

Wordpress how to get the post thumbnail inside a figure tag

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

About Contact Privacy policy Terms and conditions