• 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

Target class controller does not exist - Laravel 8

how to use extended ASCII instead of unicode in PHP

array_map triple dimensional array [duplicate]

Adding one microsecond to Datetime object in PHP

Creating Combinations of Elements

Why does using salted hash on python and php give me different results?

How can I make a full text index of the column?

Limit of log line written to Apache Errorlog from mod php error_log

How do I upload a laravel project on cPanel shared hosting?

How to remove from a multidimensional array all duplicate elements including the original?

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

mysql_result is defined but mysql_free_result warns it expected a resource

WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

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

Laravel Multi-language routes without prefix

About Contact Privacy policy Terms and conditions