• 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

protect my blog content

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

Render the content of default_filter.php in Joomla front-end

PHP array, move keys and values to new array, but mix it up

Merge column values from two arrays to form an indexed array of associative arrays

Cant seem to get the Pagination to work on my WooCommerce REST API application?

How to Display Data in Yajra Datatables Laravel 7?

Webscraping Symfony/Panther: Can't get HTML

Not able to access model in the controller mautic

Sliders in Laravel

Login if user is active using Laravel Breeze

Laravel 5 controller sending JSON integer as string

Server-sent events in PHP (without echo or print)

How to write PHP in XSLT

WHM Enabling mod_rewrite

About Contact Privacy policy Terms and conditions