doubairan4213 2018-11-02 12:55
浏览 59
已采纳

Laravel:跳过数据库通知

I am trying to send the explicit via Email only using the notification class where it is configured for both ['mail', 'database']

Notification::route('mail', $shopadmin->email)->notify(new ShopadminCreated($model));

But it still goes into toArray() method and generates error.

The reason is, I am using the same class to renotify using email but this time no database entry need to be created.

  • 写回答

1条回答 默认 最新

  • doupian6118 2018-11-05 06:36
    关注

    Solution:

    After stumbling upon the Documentation on Notification. I tried this block of code and implement with below modification:

    ShopadminCreated.php:

    ...
    public function via($notifiable)
    {
        return $notifiable->prefers_email ? ['mail'] : ['mail', 'database']; 
        //return ['mail', 'database'];
    }
    ...
    

    Controller:

    $data = $notification->data; // Array fetched from database
    $model = Admin::hydrate([$data])[0];
    $model->setAttribute('prefers_email', true);
    
    Notification::send($shopadmin, new ShopadminCreated($model));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏