• 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

Assets not referencing to public folder (Laravel)

Access denied for user 'homestead'@'localhost' (using password: YES)

Fatal error: Array callback has to contain indices 0 and 1

httpd.conf on Windows: can't locate API model structure `php8_module`

(Laravel) How to delete multiple models including optional relationships?

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

How to convert binary string to normal string in php

Composer fails with kylekatarnls/update-helper on new homestead

How to send parameters in soap request in php in __soapcall() function

Laravel get user data with profile

Group data in a multidimensional array based on two columns

Nginx RTMP not recording

Passing a boolean value from checkbox in Laravel form

Transpose and flatten two-dimensional indexed array where rows may not be of equal length

How to create laravel storage symbolic link for production or sub domain system?

About Contact Privacy policy Terms and conditions