• 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

How can I format this number correctly using PHP?

Telegram bot doesn't answer

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Laravel: HTML in notification

Unsure why I am getting: Number of variables doesn't match number of parameters in prepared statement

WooCommerce Subscriptions: Remove role on cancelled subscription

Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"

Laravel: Why is my variable not being set while it's in the construct function of the controller?

Extract house numbers from address string

Pagekite error: FAIL: localhost:8080 is down

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

Auto increment id JSON

Store multiple fields in JSON column (Nova CMS)

could not find driver Debian SQL Server PHP

Shortcode or PHP inside a shortcode in Wordpress

About Contact Privacy policy Terms and conditions