User 模型中新增 markAsRead () 方法 的疑问?

在 app/Models/User.php 中新增 markAsRead() 方法, 去除顶部未读消息标示的功能 —— 当用户访问通知列表时,将所有通知状态设定为已读,并清空未读消息数。

里面的 $this->unreadNotifications->markAsRead(); —— 前面 $this->unreadNotifications 可以理解, 用于获取该用户的所有未读消息, 调用的是User模型里面的Trait Notifiable。 但后面的markAsRead(),是在哪里定义的呢?

class User extends Authenticatable
{
    public function markAsRead()
    {
        $this->notification_count = 0;
        $this->save();
        $this->unreadNotifications->markAsRead();
    }
}
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

@啊星 Illuminate\Notifications----》DatabaseNotification.php

5年前 评论
讨论数量: 4

清空标记也要把nitifications表里面的read_at的时间也要修改,看下面就懂了
file

file

5年前 评论

@tudous markAsRead()这个函数在哪里定义的呢?

5年前 评论

@啊星 Illuminate\Notifications----》DatabaseNotification.php

5年前 评论

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