• 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

How to get AJAX to post on second page?

Zig-zag scan an N x N array

Image upload not working through ajax Laravel

PHP DOTENV unable to load env vars

PHP password_verify

Get orders by date and status woocommerce

renameColumn migration fails for existing column with columns does not exist error

PHP 8 - libxml_disable_entity_loader() has been deprecated. How do I replace the functionality it provides?

Performance of foreach, array_map with lambda and array_map with static function

Get all WooCommerce products within own plugin

Cache clear probem in Larave

Can't call javascript alert alertify library from PHP

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

woocommerce get_order_report_data to show order_item_id

Inserting Country Selection into MySQL PHP [duplicate]

About Contact Privacy policy Terms and conditions