• 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

Hi, I am making a contact form thingy, and my php isn't working any reason why?

Remove categories with all childs derived from parent category

Laravel 8 factory state afterCreating

Send same name multiple checkbox values via ajax

RabbitMQ PRECONDITION_FAILED - unknown delivery tag

Laravel Nova, route not found

How to retrieve Active Directory group policy maximum password age using LDAP

How can I access an array/object?

str_replace or preg_replace random number from string

PHP contact form configuration [duplicate]

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Cache clear probem in Larave

Artisan, creating tables in database

Image upload not working through ajax Laravel

How to get array values using foreach in laravel

About Contact Privacy policy Terms and conditions