• 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

Limit login attempts in Laravel 5.7

laravel 5.6 bulk inserting json data

How to get Laravel's CSRF Token from Another Website?

How to get values inside <![CDATA[values]] > using php DOM?

WHM Enabling mod_rewrite

How can I make good efficent AJAX live forms with just jQuery and

Auto increment id JSON

How to upload mpdf file after generating to s3 bucket in php

backup files to google drive using PHP

Dropzone: Submit both form data and dropzone at once

Show date difference as "20" instead of "20 years ago"

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

In PHP, which is faster: preg_split or explode?

I cannot create a auto generated date time in mysql workbench

Invalid value in field "itemtype" in Google Search Console

About Contact Privacy policy Terms and conditions