$this->unreadNotifications->markAsRead ();里面的 unreadNotifications 是什么?

这里的$this->unreadNotifications指的是什么呢

public function markAsRead()
    {
        $this->notification_count = 0;
        $this->save();
        $this->unreadNotifications->markAsRead();
    }
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

使用了 Notifiable 这个 trait

file

file

file

6年前 评论
讨论数量: 9
KayuHo

未读的通知

6年前 评论

@Joy_he 字面意思我是理解,只是不知道它是谁的属性或是谁的对象,IDE无法对其溯源

6年前 评论

使用了 Notifiable 这个 trait

file

file

file

6年前 评论

@Spike 我们知道,$user->topics返回的是数据集合,$user->topics()返回的是数据库的查询语句,因此$user->topics == $user->topics()->get()。那么想问问,这里的$this->unreadNotifications->markAsRead()为什么不是用$this->unreadNotifications()->markAsRead() ? 还是说这个是用了魔术方法的,像Dingo Api的$this->response == $this->response() ,是这样么?如果是的话,那我怎么知道那些是用了魔术方法的啊?

5年前 评论

@Spike 我也是不清楚这个是什么意思,这也藏得太深了吧!

5年前 评论

@lianglunzhong 你可以打印看看 this->unreadNotifications 返回的是什么。实际上返回的是 DatabaseNotificationCollection, 这个类里有你想要的答案

5年前 评论

@lianglunzhong https://laravel.com/api/5.7/Illuminate/Not...
https://laravel.com/api/5.7/Illuminate/Dat...
$this->unreadNotifications()和$this->unreadNotification是不同的对象类型,看上面的两个API文档就知道了,laravel文档很多地方写的并不详细,参考下这个API文档就会好很多了

5年前 评论

toDabase() 估计这个是前提?
$user->notify($instance) 发通知?
$user->notifications()->get() 获取通知?
users表中的notification_count 只是通过导航的badge通知用户?
$user->unreadNotifications->markAsRead() 标记通知已读?

文档基本看不懂 so。。。!

5年前 评论

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