• 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

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

How to keep value of selected value after form submission?

send email using gmail-api and google-api-php-client

How to get AJAX to post on second page?

PHPExcel file download using AJAX call

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

Laravel database insert with combining array and string

PHP Print to Network Printer

Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path: ) in Unknown on line 0

laravel MVC execution flow

How to update array value in Laravel

auth pages not getting css in laravel

Convert date and time to Jalali in Laravel

Cannot connect to own websocket server when on secured domain

PHP Form Not Inserting

About Contact Privacy policy Terms and conditions