• 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

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

How to upload mpdf file after generating to s3 bucket in php

How do I call a php file with axios?

Adding custom body class to the custom archive pages

Json_Encode not returning html even i try to encode JSON_HEX_QUOT | JSON_HEX_TAG

Laravel 8: Array to string conversion while calling route:list

PHP web3 ERC20 token function call

Laravel 8 factory state afterCreating

how to sort by a custom appended relation to model

If you intend you use SMTP, add your SMTP Code after this Line

How to submit the custom form data in database in WordPress without plugin using ajax?

Inserting data into SQL Server Db An Invalid direction was specified

Batch request Google Calendar php API

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

php echo remove slashes from url [duplicate]

About Contact Privacy policy Terms and conditions