• 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

PHP only Hit Counter?

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

GA4 custom event from server side, can someone tell me how i can do the following code in php?

phpunit - mockbuilder - set mock object internal property

Laravel: Create morphs() relationship nullable

Add restriction to WooCommerce coupons by allowed user ID

How to reset Laravel AuthManager/guards in between API calls in tests?

array_map triple dimensional array [duplicate]

How can I get new CSRF token in LARAVEL by using ajax

get data-value with variable value

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

What will the best solution for this multiple optional filter?

HTML and PHP in one file

php echo remove slashes from url [duplicate]

Create tags in laravel post publishing

About Contact Privacy policy Terms and conditions