• 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

What's the net::ERR_HTTP2_PROTOCOL_ERROR about?

Problems getting instance of UploadedFile in Yii2

PHP 8.1: strftime() is deprecated

Convert PHP array into HTML tag attributes separated by spaces

httpd.conf on Windows: can't locate API model structure `php8_module`

How to pass security cloudflare server with php curl

Auto increment id JSON

MOODLE: What does it mean to aggregate h5p assets?

Move a child array to parent array and change parent/child name

PHPExcel export HTML table to xlsx

Implode array with array of glue strings

PHP contact form configuration [duplicate]

Laravel 5.1 how to use {{ old('') }} helper on blade file for radio inputs

Unable to match results of php hash_hmac() and coldfusion hmac()

how to upload binary image to sql server using php laravel

About Contact Privacy policy Terms and conditions