• 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

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel

Changing font color in javascript

"There is no active transaction" when refreshing database in Laravel 8.0 test

How to convert a carbon into string, to take the date only?

MySQL order by field in Eloquent

Nginx RTMP not recording

Cannot pass null argument when using type hinting

Log a user out of a website when they put their computer to sleep

Detect emoticons in string

JSON Render Issue in Date Object Laravel and PHP 7.4

Handling expired token in Laravel

Unable to guess the mime type as no guessers are available Laravel 5.2

Laravel Pagination links() not working

calling server using nusoap with complextype

How to update array value in Laravel

About Contact Privacy policy Terms and conditions