简体   繁体   English

MailChannel 上的 Laravel 通知错误

[英]Laravel Notification error on MailChannel

I am sending a notification to a user and getting an error that I can not find much about and have not seen before sending notifications.我正在向用户发送通知并收到一个错误,在发送通知之前我找不到太多相关信息并且没有看到。

Trying to get property 'view' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'view' of non-object at /app/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php:92)


public function toMail($notifiable)
    {
        $start = Carbon::today()->subDay(1);
        $end = Carbon::today();
        $events = Event::whereBetween('created_at',[$start,$end])
            ->whereNull('eventbrite_id')
            ->count();

        $users = User::whereBetween('created_at',[$start,$end])
            ->count();

        (new MailMessage())
            ->line("Overall stats for ${start} - ${end}")
            ->line("Events: ${events}")
            ->line("Users: ${users}")
            ->subject("stats for ${start} - ${end}");
    }

Then when I call the notification inn the job like this然后当我像这样调用通知旅馆时

$users  = User::where('id',1)->get();
        Notification::send($users,new DailyAdminStats());

I get that error.我得到那个错误。 I tried deleting all the carbon dates for the mail message and that did not work so its not anything with carbon.我尝试删除邮件消息的所有碳日期,但没有用,所以它与碳无关。 Really confused on what the error is and how to fix it.对错误是什么以及如何修复它真的很困惑。

For me, it was an issue with the code before the (new MailMessage()) line.对我来说,这是 (new MailMessage()) 行之前的代码的问题。 I would comment all the code before this and send a dummy message to see if it works.我会在此之前评论所有代码并发送一条虚拟消息以查看它是否有效。 Then add the lines to identify the error in your code.然后添加行以识别代码中的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM