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

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

public function markAsRead()
    {
        $this->notification_count = 0;
        $this->save();
        $this->unreadNotifications->markAsRead();
    }
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

使用了 Notifiable 这个 trait

file

file

file

7年前 评论
讨论数量: 10
KayuHo

未读的通知

7年前 评论

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

7年前 评论

使用了 Notifiable 这个 trait

file

file

file

7年前 评论

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

6年前 评论

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

6年前 评论

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

6年前 评论

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

6年前 评论

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

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

6年前 评论