• 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 -> Next nearest date defined by array of days in week

how to redirect the user back to desired URL after login page in PHP?

Laravel database insert with combining array and string

php curl_exec() Connection refused when retrieving a remote image

Auto increment id JSON

Custom API and cunsuming in php?

How to prevent phpmailer sending embedded image as an attachment on Gmail?

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

Doctrine 2 mapping referencing unique key

using random function but it's displaying duplicates

How to add a custom field to all Woocommerce attribute terms using add_action

Whats the point of running Laravel with the command 'php artisan serve'?

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

Laravel Get Days In Month From Month Number?

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

About Contact Privacy policy Terms and conditions