• 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

How to override htaccees file for cache control header

image source not readable

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

Laravel Excel::store file empty after stored

how to fix Service provider class not found when using repository?

How to get AJAX to post on second page?

Eloquent insert id with sequence next value

Clients authentication and user authentication with laravel

jQuery Ajax Post with data

Using spatie/media-library, how to rename a collection of uploaded files?

Get sum of arrays inside array

Lumen - Postgresql setup - Composer

Failing validation doesn't stop code execution in livewire component

Laravel dosen't connect with Oracle

Return multiple values from a function using mysqli_fetch_assoc [closed]

About Contact Privacy policy Terms and conditions