• 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

Attempted to call an undefined method named "get" of class "MailController"

Combining a describing and one array with data

Could not decode a text frame as UTF-8.

Shopify password update using Shopify API

Custom post type single page not working

How to get Laravel's CSRF Token from Another Website?

How to read laravel_session cookies saved in cookie memory of browser in client side?

enable Apache http Authorization header

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)

Fetch files from next cloud storage and display in Laravel website

Laravel database insert with combining array and string

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

php mysql + create a friend request system

Symfony autowiring issues since docker update

OAuth2 Token PHP

About Contact Privacy policy Terms and conditions