• 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

PHP Slim Framework request using withAttribute error

JQuery content editable div and text box on submit not sending POST

Calculating Median of an array in PHP

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

Using Associative arrays

Laravel whole batch is cancelled if one Job fails

How to add a custom field to all Woocommerce attribute terms using add_action

Pass an image through AJAX [duplicate]

Filter WooCommerce related products by Polylang language

phpunit - testing is painfully slow

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

Elastic Beanstalk with Laravel Envoy

Laravel 8 factory state afterCreating

Assets not referencing to public folder (Laravel)

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

About Contact Privacy policy Terms and conditions