• 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

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

Return new collection without modifying original collection

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

Put content of wordpress page inside div

Extract string between first whitespace and last whitespace in php

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Currently Using CodeIgniter Framework i have an Error

Creating command to backup MySql database in Laravel

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

Whats the point of running Laravel with the command 'php artisan serve'?

Google API Heatmap Layer exception, why?

Extract house numbers from address string

Laravel You requested 1 items, but there are only 0 items available

Log file is not being written in Laravel 5.5

generating a random code in php?

About Contact Privacy policy Terms and conditions