Answer the question
In order to leave comments, you need to log in
Laravel. When to use Events and when Notifications?
Hello.
Action A is performed in the controller. A record is inserted into the database. In principle, there is no need to call any events, because this action does not entail any other actions and is performed only in one place. But I need to notify the user on the frontend about this. When using broadcasting from Notifications, there is no way to specify the channel name, so this option does not suit me (I'm not considering writing my own driver yet). I am using Events. I created the Event. The Event Listener has not even been created yet. In Event'e included broadcasting in the required private channel.
Now I need to use Notifications to the database. Write the same data that goes to the frontend via sockets.
A selection of users will be made. These users will receive notifications in the database:
Notification::send($users, new InvoicePaid($invoice));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question