• 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

Store multiple fields in JSON column (Nova CMS)

How to skip cart page on woocomerce for certain products only?

How to convert a carbon into string, to take the date only?

Laravel update hasMany relationship using saveMany

How to KeyBy where multiple items have the same key

How to install php yaml on CentOs?

MOODLE: What does it mean to aggregate h5p assets?

Laravel SQL query midnight time not showing

PHP Form Not Inserting

Mysqli Output to a table

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

How to Generate PDF invoice to XML format using mPDF

Change the alert text on add to cart action without selected variation in Woocommerce

Laravel post contact form giving me error 419

About Contact Privacy policy Terms and conditions