• 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 skip cart page on woocomerce for certain products only?

Which is faster php date functions or carbon?

Populate Dynamic Dropdowns List in Codeigniter

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

PHP only Hit Counter?

Distribute array row data to make multiple new rows

Assets not referencing to public folder (Laravel)

How can I make this nested location configuration use the correct path to call a php program?

PHPMyAdmin not working as intended at remote server. Error 500, $respond not found

How to make dot match newline characters using regular expressions

phpunit - mockbuilder - set mock object internal property

PHP my timezone is no setting up in PHP.ini File in xampp

PhpSpreadSheet: How to save Workbook sheets in individual CSV files

ldap is missing from system when installing adldap2 in laravel

PHP: How to quickly split a key=value file into associative array

About Contact Privacy policy Terms and conditions