• 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

Having issue with matching rows in the database using PDO

Form Validation and Submission to database

Passing a boolean value from checkbox in Laravel form

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

PHP Find Array Index value in multi-line array

Display a product custom field only in WooCommerce Admin single orders

Insert a DIV after the 6th product only once in WooCommerce category archives

how to pass row id in href of a tag in codeigniter controller?

Connecting an HTML webpage to a SQL Server

Laravel Displaying image from database

php echo xml documents with header

Symfony 4: how to allow dynamic values for array nodes in bundle configuration?

how to upload binary image to sql server using php laravel

Use same method for inertia response and json response Laravel Jetstream

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

About Contact Privacy policy Terms and conditions