• 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

Debugging Stripe Webhook Event

file_put_content...fail to open stream:Permission denied in Laravel 5

Loading data from MySQL and populating dropdown select with jQuery Mobile, PHP

Laravel 4 Redirect::back() not going to previous page (refreshing current page)

Clients authentication and user authentication with laravel

Laravel Livewire: jQuery not working in child component loaded via @if statement

CONCAT columns with Laravel 5 eloquent

Cut an arabic string

Multiply each value in array using array_map function

Require a class from another class - php

Why is this PHP array not the same?

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

how to hide previous markers when new markers added in google map javascript api

Limit login attempts in Laravel 5.7

javascript html popup window

About Contact Privacy policy Terms and conditions