PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] Laravel - should send notification method

 January 28, 2022     laravel, notifications     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing