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

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

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

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 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');
}
6年前 评论

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