Categories: laravel
Real-time WebSocket is pretty amazing. It is fun to have this technology in your application. The communication is being push to you instead of you requesting it. It is great to have this type of communication when your application is a monitoring service.
Laravel Reverb and Pusher provides realtime update service. Laravel Echo integrates with these two service seamlessly. If you are building monitoring service for the web, these stacks are very good choice.
If you are building this with Laravel, these are the initial integration pain I went through. I hope by listing them here will get you up and running even faster.
-
Laravel Queue is by default using database. That means if you are broadcasting event using
dispatch
, make sure you havephp artisan queue:work
running. Otherwise, you can change theQUEUE_CONNECTION
tosync
. -
cors
is a pain, but Laravel has made it easy to deal with. If you are running intocors
issue, just dophp artisan config:publish cors
and look intoconfig/cors.php
should most likely resolve your issue. -
Sanctum config has a pretty standard out of the box setup. If you are not sure, just add your application’s domain (with port) to
SANCTUM_STATEFUL_DOMAINS
in.env
. -
Use
axios
. It takes care of XSRF with just addingwindow.axios.defaults.withXSRFToken = true;
. I also likewindow.axios.defaults.headers.common['Content-Type'] = 'application/json';
. -
The
Network
tab andWS
filter in Chrome Devtool is your friend working with real-time update service. Look for the protocol you are using and read theMessages
will give you a lot of information on troubleshooting. -
It took me a while to figure out, but with Laravel 11, moving
channels.php
to->withBroadcasting()
with onlyauth:sanctum
middleware does not work. I got it to work after addingapi
middleware. I have a pull request open, maybe we will see if the issue I found is relevant. -
I have a better time creating SPA with default Vue app over Nuxt. It is probably skill issue.
skill issue
— ThePrimeagen (@ThePrimeagen) July 24, 2023