• 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

Prestashop webservice API creating cart rules

Laravel 8 Multiple Relationships for Factory

Login if user is active using Laravel Breeze

Magento Installation SQLSTATE[HY000] [2002] No such file or directory error

How to generate QR CODE for dynamic generating link and logo using Simple QrCode in laravel?

selected value from the listbox in php

I need to link Google Sheet with my Laravel

Can't find vendor/autoload.php for Ratchet

Laravel dosen't connect with Oracle

How to submit the custom form data in database in WordPress without plugin using ajax?

PHP Print to Network Printer

Send same name multiple checkbox values via ajax

Laravel unique validation on multiple columns

Use same method for inertia response and json response Laravel Jetstream

Convert date and time to Jalali in Laravel

About Contact Privacy policy Terms and conditions