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

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

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

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 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();
        }
    }
4年前 评论

文档中讲的很清楚了:消息通知《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();
        }
    }
4年前 评论

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

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

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