• 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

woocommerce_wp_select options array from product attribute terms

Last order would be re-order in wooCommerce. How is it possible?

How to convert binary string to normal string in php

Phpunit partial mock + proxy Entity

I want to display default profile image if user do not have profile image

How to redirect to another page and call a Function there on Angular ng-click

Laravel 5.1 xmlHttpRequest AJAX POST TokenMismatchException

How can I get new CSRF token in LARAVEL by using ajax

How can I pass the list to the component variable in Laravel?

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

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

Problems getting instance of UploadedFile in Yii2

Fatal error: Trait 'LaminasDbAdapterLaminasDbAdapterAdapterInterface' not found in /var/www/vendor/laminas/laminas-db/src/Adapter/Adapter.php

How to override htaccees file for cache control header

protect my blog content

About Contact Privacy policy Terms and conditions