• 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

Insert database rows from columns of data from associative array of indexed arrays

Cut an arabic string

Add bold text and line break into Laravel Notification Email

PHP sort array of objects by two properties

Fatal error: [] operator not supported for strings

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

How to install PHP composer inside a docker container

"cannot list resources" error from WooCommerce REST API

Artisan, creating tables in database

Limit login attempts in Laravel 5.7

SlimExceptionHttpNotFoundException

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

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

Doctrine ORM: Excluding Records Based on Values of Nested Relationships

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

About Contact Privacy policy Terms and conditions