• 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

Losing session data after POST from third party website

Refresh specific HTML content that retrieves data from MySQL

Make survey at laravel 5.4 and MySQL

Can't call javascript alert alertify library from PHP

Get sum of arrays inside array

virtctl works when executed via command line but not from php exec()

Telegram bot doesn't answer

Laravel Carbon get start + end of last week?

how to validate form data in codeigniter 4

How to get Laravel's CSRF Token from Another Website?

Laravel Nova, route not found

How to override htaccees file for cache control header

Sentry + Laravel: how to log an already catched Exception?

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

Update Total in checkout of Woocommerce with Ajax Request

About Contact Privacy policy Terms and conditions