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();
}
}
推荐文章: