• 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

Extract string between first whitespace and last whitespace in php

Laravel get user data with profile

PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT "INOUT")

How to install php_imagick on wamp64

Encrypt in php and decrypt in Dart(flutter)

Login if user is active using Laravel Breeze

retrieve data from database using session

Laravel 5.1 xmlHttpRequest AJAX POST TokenMismatchException

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

Send Outlook 2010 email using PHP

Laravel/ PHP: Order By Alphabetical with numbers in order [duplicate]

Display the default discounted price and percentage on Woocommerce products

Attempted to call an undefined method named "get" of class "MailController"

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

About Contact Privacy policy Terms and conditions