• 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

Need to display only array value in JSON output

Laravel Sanctum CSRF not authenticating

Unable to run composer install

Laravel passport auth token not working after moving to different server

Display a product custom field only in WooCommerce Admin single orders

PHP SoapClient: set a namespace without prefix

PHP Deprecated issue when running artisan command

How to get array values using foreach in laravel

VB.NET WebRequest with PHP POST

wp_remote_get() not passing authentication

Server-sent events in PHP (without echo or print)

Problems getting instance of UploadedFile in Yii2

PHP using str_starts_with for array to exclude same as with wildcard

php code to send checkbox form results to email

CONCAT columns with Laravel 5 eloquent

About Contact Privacy policy Terms and conditions