• 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 get the header value, if we don't know the value because the value is random from the server

Laravel print last executed SQL query with Query log

Laravel - Browser displays message again when I press back button

Add bold text and line break into Laravel Notification Email

Laravel Pagination links() not working

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

Performance of foreach, array_map with lambda and array_map with static function

Sliders in Laravel

Creating Combinations of Elements

Make Shipping Method fields Mandatory on Woocommerce checkout page

How can i hide dt if dd got empty value

Login if user is active using Laravel Breeze

PHP using str_starts_with for array to exclude same as with wildcard

printing all running session variable in laravel 5.1

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

About Contact Privacy policy Terms and conditions