• 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

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

Laravel 5.2: Unable to locate factory with name [default]

Spam Filter in Contact Form

phpunit - testing is painfully slow

If action is on a different page do I use fwrite function

How to Display Data in Yajra Datatables Laravel 7?

generate an Excel file using PHP

enroll_table three field fetch to payment form to create payment field in laravel 5.5

Use same method for inertia response and json response Laravel Jetstream

Need to display only array value in JSON output

Laravel Gates using model and returns "Using $this when not in object context" Line 28 of AzureUser model

Limit login attempts in Laravel 5.7

Log a user out of a website when they put their computer to sleep

Laravel - Browser displays message again when I press back button

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

About Contact Privacy policy Terms and conditions