• 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

SQLSTATE[HY000]: General error: 1 table posts has no column named *

PHPExcel How to set conditional formatting to change cell background color based on cells values

Yii2: How do I debug console commands?

How can I make this nested location configuration use the correct path to call a php program?

Add record for each array elements if missing in table

How to increase the PHP upload limits [duplicate]

how to see if database exists with PDO [duplicate]

PHP Deprecated issue when running artisan command

Get WooCommerce product variation attribute terms in admin products general box

Laravel: HTML in notification

Confirm Leave on External Links in Wordpress

correct PHP headers for pdf file download

Sum array values of a column within each column of an array with 3 levels

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"

Star and Half Star Rating in Laravel

About Contact Privacy policy Terms and conditions