• 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

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

Printing more than one array using print_r or any other function in php

Changing font color in javascript

Laravel s3 upload file with metadata using pre-signed url

Transpose csv file data [duplicate]

How To Access A Column In M-M Relationship Table In Laravel

Why i get wrong output for html markdown?

Laravel Schedule not sending email

Call to a member function fetch_field() on a non-object MySQLiDB

Laravel phpunit test failing authorization

get data-value with variable value

PHP file_get_contents function

PHPExcel export HTML table to xlsx

The sum of the user's points

Check if a string contain multiple specific words

About Contact Privacy policy Terms and conditions