To use Laravel Echo in a blade file without Vite/Mix, you can include the necessary scripts in the blade file itself. Here's how:
- In your blade file, include the following scripts:
<script src="https://cdnjs.cloudflare.com/ajax/libs/laravel-echo/1.11.0/echo.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pusher/7.0.3/pusher.min.js"></script>
- Initialize Echo in your blade file:
<script>
window.Echo = new Echo({
broadcaster: 'pusher',
key: '{{ env('PUSHER_APP_KEY') }}',
cluster: '{{ env('PUSHER_APP_CLUSTER') }}',
forceTLS: true
});
</script>
- Now you can use Echo in your blade file:
<script>
Echo.channel('some_channel')
.listen('OrderShipmentStatusUpdated', (e) => {
console.log("broadcast received");
});
</script>
Note: Make sure to replace the PUSHER_APP_KEY and PUSHER_APP_CLUSTER values with your own Pusher credentials.