7.5. 未读消息统计

本教程最新版为 9.x,当前版本已放弃维护,请阅读最新版本!

未读消息数量

file

在网页端,用户有未读消息了,会在 header 中有红色提示。对于 APP 来说,需要一个接口查询当前用户 未读消息数量

1. 增加路由

routes/api.php

.
.
.
// 通知列表
$api->get('user/notifications', 'NotificationsController@index')
    ->name('api.user.notifications.index');
// 通知统计
$api->get('user/notifications/stats', 'NotificationsController@stats')
    ->name('api.user.notifications.stats');
.
.
.

这里我们设计为 user/notifications/stats ,stats 是 statistics 的缩写,意思是统计,这个接口可以直观的表述为——我的通知数据统计。

2. 修改 Controller

app/Http/Controllers/Api/NotificationsController.php

.
.
.
public function stats()
{
    return $this->response->array([
        'unread_count' =>...

本文章首发在 LearnKu.com 网站上。

为了保证课程的高品质,我们需要对课程进行收费。付费后 才能观看剩余内容。 购买

上一篇 下一篇
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
贡献者:1
讨论数量: 4

stats 方法是错误了吗?
1 个点赞 | 3 个回复 | 问答 | 课程版本 5.5
JunLee
kitty
关于 $this->user 和 $this->user() 的理解
0 个点赞 | 2 个回复 | 分享 | 课程版本 5.8