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

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

6年前 评论
讨论数量: 4

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

file

6年前 评论

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

6年前 评论

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

6年前 评论

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