• 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 implement placeholder in a php file for moodle plugin?

How to fix 'Data has already been sent to output, unable to output PDF file' in MPDF

Custom post type single page not working

Why the name of trucks are same in 2nd and 3rd record of company data retrieval?

renameColumn migration fails for existing column with columns does not exist error

PHP DOTENV unable to load env vars

Laravel Delete and Update

PHP block shortcut in Visual Studio Code

How to map the two arrays with a duplicate value?

Edit product hook WooCommerce

Error Class "LaravelFortifyFeatures" not found

Log file is not being written in Laravel 5.5

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

How to change the app environment at run time?

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

About Contact Privacy policy Terms and conditions