• 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 get company posts from LinkedIn via API?

how to create html table in php

PHP file_get_contents function

How to break out of a foreach once a condition is met?

Laravel - How to properly generate unique slugs from article titles?

Split array into 4-element chunks then implode into strings

PHP: How to raise number to (tiny) fractional exponent?

xdebug 3 not working in ubuntu 20.04 with docker

Upgrade PHP on AWS Linux

Laravel MSSQL Server Connection not working

how to prevent float variables displaying as scientific notation when printing [duplicate]

How avoid Moved Permanently The document has moved here

How do I do HTTP basic authentication using Guzzle?

add_action() function in wordpress not working [duplicate]

How to Install Composer Require doctrine/dbal

About Contact Privacy policy Terms and conditions