• 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 render html from a @foreach loop in a textarea

php script to delete files older than 24 hrs, deletes all files

Custom post type single page not working

PHP rotate matrix counter-clockwise

How to disable only_full_group_by option in Laravel

protect my blog content

PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"

Laravel 8: Array to string conversion while calling route:list

PHPMyAdmin not working as intended at remote server. Error 500, $respond not found

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

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

Add Class in html Dynamically in PHP

php: command not found Command PhaseScriptExecution failed with a nonzero exit code

Sum array values

Remove country code from phone number?

About Contact Privacy policy Terms and conditions