• 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 get multiple values with same key from an array PHP

How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

Laravel-fopen: failed to open stream: Permission denied

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

How to fix Call to undefined method AppModelsTableName::factory?

Clear javascript source cache laravel 5.8

Submitting a form with ajax in Wordpress

How to install PHP composer inside a docker container

str_replace or preg_replace random number from string

Yii2 select2 database exception number of bound variables does not match number of tokens

str_word_count() function doesn't display Arabic language properly

Getting output of MS stored procedure on php call

Losing session data after POST from third party website

dockerizing Laravel + vue

Laravel passport auth token not working after moving to different server

About Contact Privacy policy Terms and conditions