【问题标题】:Laravel send notification to different notifiables based on send methodsLaravel 根据发送方法向不同的通知发送通知
【发布时间】:2021-04-24 11:16:41
【问题描述】:

我有一个应用程序可以向管理员发送有关某些用户操作的通知。一些管理员应通过 SMS 通知,而其他管理员应仅通过数据库通知。 做这个的最好方式是什么?使用两个通知还是只使用一个?我没有找到通过通知中的通知方法更改通知的任何方法。

有什么建议吗?

【问题讨论】:

    标签: laravel notifications laravel-notification


    【解决方案1】:

    它可以与If语句一起使用

    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;
        }
    }
    

    【讨论】:

    • 谢谢,我早就知道这种方式了,但没注意,因为我在设置表中保存了管理员的通知方式。现在你的回答让我明白了?。
    猜你喜欢
    • 2021-01-23
    • 2020-11-28
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    相关资源
    最近更新 更多