• 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

Laravel Jetsream Profile page not loading on fresh install

How to create a scheduler application in php

How to programmatically find public properties of a class from inside one of it's methods

Require a class from another class - php

Log file is not being written in Laravel 5.5

Populate Dynamic Dropdowns List in Codeigniter

Symfony Mercure "Failed to send an update"

laravel sanctum Route [login] not defined

ORA-12546: TNS:permission denied error connection to remote oracle server

Laravel: Why is my variable not being set while it's in the construct function of the controller?

PHP Array split string and Integers

How to check user Permissions using Custom Middleware in Laravel

Normalize DateInterval in PHP

Laravel Get Days In Month From Month Number?

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

About Contact Privacy policy Terms and conditions