• 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

could not find driver Debian SQL Server PHP

Additional price based on cart item count in WooCommerce

Undefined variable in Laravel 8 project (php 7.4)

How to pass data to all views in Laravel 5?

How to Mock the Request Class in Laravel?

Target Laravelista is not instantiable

Form Validation and Submission to database

using random function but it's displaying duplicates

oauth-private.key does not exist or is not readable

How can I convert from a{a{} b{}} to a[a[],b[]] using php preg_match?

How to test a php login connected to a mysql db through xampp?

Stop caching for PHP 5.5.3 in MAMP

Composer fails with kylekatarnls/update-helper on new homestead

How to downgrade or install a specific version of Composer?

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

About Contact Privacy policy Terms and conditions