• 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

Prestashop cUrl Login

how to identify the web server name of remote host

Trying to iterate over a mongodb cursor twice - failing

Create tags in laravel post publishing

Add a custom text for a particular product on specific email notification in Woocommerce

generate an Excel file using PHP

Transform array, set each array element with parent key php

How to implement placeholder in a php file for moodle plugin?

laravel automatically deletes server.php on php artisan serve

Filter array by skipping every nth element from the end

SilverStripe unable to populate multiple member Childs

Star and Half Star Rating in Laravel

How to to send mail using gmail in Laravel?

"There is no active transaction" when refreshing database in Laravel 8.0 test

Wordpress 'post_type_link' hides permalink

About Contact Privacy policy Terms and conditions