• 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

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

how to pass row id in href of a tag in codeigniter controller?

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

Convert every two values of an associative array into key-value pairs

Can I write PHP code across multiple lines per statement?

Session timeout in Yii2

Laravel/docker-compose/redis - Class 'Redis' not found

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

How to write PHP in XSLT

How to create laravel storage symbolic link for production or sub domain system?

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

Using spatie/media-library, how to rename a collection of uploaded files?

Must be of the type array, null given,

Laravel websockets AWS EC2 - Connection failed

Batch request Google Calendar php API

About Contact Privacy policy Terms and conditions