清除未读消息标示这里遇到了一点问题

清除未读消息标示这里遇到了一点问题

这里模型中添加了这个方法 前两句我明白是什么操作,但是
$this->unreadNotifications->markAsRead();
这一句的代码是什么意思能 没看懂?

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2

文档中讲的很清楚了:消息通知《Laravel 5.8 中文文档》

标记通知已读

通常,在用户阅览一条通知之后,你会想将其标识为「已读」。 Illuminate\Notifications\Notifiable trait 提供了 markAsRead 方法,它更新数据库中通知记录的 read_at 列:

$user = App\User::find(1);

foreach ($user->unreadNotifications as $notification) {
    $notification->markAsRead();
}

可以在通知控制集合上直接使用 markAsRead 方法代替循环调用通知:

$user->unreadNotifications->markAsRead();

Illuminate/Notifications/DatabaseNotification.php

    ...

    public function markAsRead()
    {
        if (is_null($this->read_at)) {
            $this->forceFill(['read_at' => $this->freshTimestamp()])->save();
        }
    }
6年前 评论

文档中讲的很清楚了:消息通知《Laravel 5.8 中文文档》

标记通知已读

通常,在用户阅览一条通知之后,你会想将其标识为「已读」。 Illuminate\Notifications\Notifiable trait 提供了 markAsRead 方法,它更新数据库中通知记录的 read_at 列:

$user = App\User::find(1);

foreach ($user->unreadNotifications as $notification) {
    $notification->markAsRead();
}

可以在通知控制集合上直接使用 markAsRead 方法代替循环调用通知:

$user->unreadNotifications->markAsRead();

Illuminate/Notifications/DatabaseNotification.php

    ...

    public function markAsRead()
    {
        if (is_null($this->read_at)) {
            $this->forceFill(['read_at' => $this->freshTimestamp()])->save();
        }
    }
6年前 评论

unreadNotifications 方法是在 Notifiable 中的 HasDatabaseNotifications定义的方法

public function unreadNotifications()
{
    return $this->notifications()->whereNull('read_at');
}
5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!