• 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

merge all files in directory to one text file

500 (Internal Server Error) with Laravel & Docker [duplicate]

PHPExcel export HTML table to xlsx

CodeIgniter 4: Like and Dislike Functionality

Laravel 5.5 change unauthenticated login redirect url

Required field only if another field has a value, must be empty otherwise

Merge key and value of array index [duplicate]

Form repeater send wrong data with last element in Laravel

Unable to Edit config.inc.php

Transform array, set each array element with parent key php

laravel automatically deletes server.php on php artisan serve

How to override htaccees file for cache control header

XDebug not working in VScode for php debugging

PHP web3 ERC20 token function call

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

About Contact Privacy policy Terms and conditions