Anyone that comes across this. Apparently the issue itself was with livewire. (Mine was 3.0.1 and it needed to be 3.3)
I just updated it: composer update livewire/livewire
Working perfectly now
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Does the Livewire 3 @script @endscript directive even work?
I did it based on the documentation: https://livewire.laravel.com/docs/events#listening-for-events-inside-component-scripts
Yet it doesn't trigger a custom function of mine with:
@script
<script>
$wire.on('post-created', () => {
playSound("{!! asset('/source/message-beep.mp3') !!}");
});
</script>
@endscript
Infact it actually echoes the @script @endscript as words.
Am I doing something wrong? Like am I placing them in the Component Blade while they should be placed outside the component (Doesn't make sense but still asking)? Please help me... I'm making a chat widget...
(Note: I have already used:
<script>
document.addEventListener('livewire:init', () => {
Livewire.on('visitor-message-created', () => {
playSound("{!! asset('/source/message-beep.mp3') !!}");
});
});
</script>
which is working find when I don't lazy load.
Now when I lazy load the component like below, while trying the @script directive like the docs:
<livewire:visitors
:currentPath="request()->url()"
lazy
/>
Atleast it doesn't show the @script @endscript as echoed text but obviously still doesn't perform it's event recieving action)
Anyone that comes across this. Apparently the issue itself was with livewire. (Mine was 3.0.1 and it needed to be 3.3)
I just updated it: composer update livewire/livewire
Working perfectly now
Please or to participate in this conversation.