• 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

Artisan, creating tables in database

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

enroll_table three field fetch to payment form to create payment field in laravel 5.5

Laravel csrf token mismatch for ajax POST Request

Prestashop cUrl Login

Multiple order by in WooCommerce

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

Laravel passport auth token not working after moving to different server

PHP returning an error message and false

Fatal error: [] operator not supported for strings

storagelogs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

Add New Parameter to Existing URL using htaccess

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

Open a popup box after receiving result from ajax

Laravel implode array items to new lines

About Contact Privacy policy Terms and conditions