7.5. 未读消息统计
未读消息数量
在网页端,用户有未读消息了,会在 header 中有红色提示。对于 APP 来说,需要一个接口查询当前用户 未读消息数量
。
1. 增加路由
routes/api.php
.
.
.
// 通知列表
Route::get('notifications', 'NotificationsController@index')
->name('notifications.index');
// 通知统计
Route::get('notifications/stats', 'NotificationsController@stats')
->name('notifications.stats');
.
.
.
这里我们设计为 notifications/stats
,stats 是 statistics 的缩写,意思是统计,这个接口可以直观的表述为——通知数据的统计。
2. 修改 Controller
app/Http/Controllers/Api/NotificationsController.php
.
.
.
public function stats(Request $request)
{
retur...