Laravel send notification to different notifiables based on send methods

360 views Asked by At

I have an application that sends notifications to admins on some user's actions. some admins should notify by SMS and others just via database. what is the best way to do this? use two notifications or just one? I didn't found any way to change notifiables by their notify method in a notification.

Is there any suggestion?

1

There are 1 answers

1
Wailan Tirajoh On BEST ANSWER

it can work with If Statement

class yourNotifName extends Notification
{
    use Queueable;
    private $role;
    private $notif;

    public function __construct(User $user)
    {
        $this->role= $user->role;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        if($this->role == "admins") {
            $this->notif = ['sms'];
        } else {
           $this->notif = ['database'];
        }
        return $this->notif;
    }
}