• 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

PHPExcel How to set conditional formatting to change cell background color based on cells values

Creating Combinations of Elements

Laravel Displaying image from database

Dropdown with current value from Mysql

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

How to update array value in Laravel

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

PHP: How to raise number to (tiny) fractional exponent?

Must be of the type array, null given,

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

Laravel-fopen: failed to open stream: Permission denied

Can I use a WooCommerce function without any WooCommerce page?

PHP and WebView - Cookie doesn't are the same

Redis Command To Sort Keys

About Contact Privacy policy Terms and conditions