0

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 Answers1

0

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;
    }
}
Wailan Tirajoh
  • 481
  • 5
  • 17
  • Thanks, I already knew this way but I didn't pay attention to it, because I am saving the admin's notification method in the settings table. now your answer clarified me . – Pooria Anvari Apr 24 '21 at 11:39