• 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 to see if database exists with PDO [duplicate]

Declaration of OMDb::query(string $statement) must be compatible with PDO::query

How to get an Array value inside an object in an array Php [duplicate]

Phalcon: setStatusCode returns empty response

Artisan, creating tables in database

add " ? " in url via htaccess RewriteRule

Using array_intersect on a multi-dimensional array

Sentry + Laravel: how to log an already catched Exception?

Symfony - "framework.test" config is not set to true

Converting alphabet letter to alphabet position in PHP [duplicate]

What's the net::ERR_HTTP2_PROTOCOL_ERROR about?

Applying programmatically a coupon to an Order in WooCommerce3

PHP usort() order in case of equality

How to use PHPCBF to fix one issue at a time?

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

About Contact Privacy policy Terms and conditions