How in Laravel run JavaScript code stored in php variable?
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>