• 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

How to create a video stream from a single dynamic image in PHP

how to create html table in php

How to disable only_full_group_by option in Laravel

Reorder attribute dropdown terms in Woocommerce single variable products

How to add automatically collapse/expand in content wordpress (single.php)?

Target class controller does not exist - Laravel 8

PhpSpreadSheet: How to save Workbook sheets in individual CSV files

How to update array value in Laravel

How to prevent phpmailer sending embedded image as an attachment on Gmail?

How to send parameters in soap request in php in __soapcall() function

Get number of working days between two dates in PHP [duplicate]

Handling expired token in Laravel

How to validate tin and cst using PHP?

Laravel lang slug in url

PHP Imap , php 7.4.3 on mac osx catalina

About Contact Privacy policy Terms and conditions