• 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

virtctl works when executed via command line but not from php exec()

Implode array with array of glue strings

Sentry on Symfony: how to exclude `NotFoundHttpException`

How can I access an array/object?

Google Calendar API batch request PHP

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

php 7 php.ini upload_max_filesize not working

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

Merge key and value of array index [duplicate]

PHP using str_starts_with for array to exclude same as with wildcard

Eloquent insert id with sequence next value

Laravel - Browser displays message again when I press back button

how to upload binary image to sql server using php laravel

How to increase the PHP upload limits [duplicate]

Target class controller does not exist - Laravel 8

About Contact Privacy policy Terms and conditions