• 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

WordPress Security Standards want me to escape my html, but how to do it correctly?

Remove country code from phone number?

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

MongoDB Duplicate Documents even after adding unique key

Correct way to use LIKE '%{$var}%' with prepared statements?

How to disable only_full_group_by option in Laravel

Update Total in checkout of Woocommerce with Ajax Request

Cut an arabic string

Two buttons one form

Laravel Factory not calling callback 'afterCreating'

Calculating Median of an array in PHP

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

Dynamic dropdown Ajax PHP request

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

About Contact Privacy policy Terms and conditions