Issue
I have this configuration where the user can set which notification it wants to receive, I don't want to do an If on every method that I call notify
.
I'd like to know if is there a method inside my notification class that I can do this validation, or how could I do that.
I thought about a solution, but it seens durty, I could validate inside via
and just return an empty array if the user setted to not receive
And I also find out a method inside Illuminate\Notifications\NotificationSender
called shouldSendNotification
but I don't know how I could overwrite it, or even if it is using this class, cause it seens to be only for queue
OBS: Laravel 7
Solution
via
would previously have been the best place for this, but Laravel now supports shouldSend
on the notification for exactly this behaviour.
/**
* Determine if the notification should be sent.
*
* @param mixed $notifiable
* @param string $channel
* @return bool|null
*/
public function shouldSend($notifiable, $channel)
{
if ($user->isUnsubscribed()) {
return false;
}
}
Answered By - Dwight
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.