• 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

PHP array_filter with arguments

codeigniter 4 running error first time with xampp

PHP array, move keys and values to new array, but mix it up

Inserting Country Selection into MySQL PHP [duplicate]

Laravel query builder binding parameters more than once

Change the alert text on add to cart action without selected variation in Woocommerce

Convert regular text to array using notepad++

if statement inside concatenation

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

Laravel insert dynamic input values with radio button

Eloquent insert id with sequence next value

How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?

JQuery content editable div and text box on submit not sending POST

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

Composer Warning: openssl extension is missing. How to enable in WAMP

About Contact Privacy policy Terms and conditions