「分享」自己写的标记单条消息为已读
routes/api.php
// 标记单条消息通知为已读
$api->put('user/read/notifications/{notification}', 'NotificationsController@readSingle')
->name('api.user.notifications.readSingle');
app/Http/Controllers/Api/NotificationsController.php
//标记单个消息通知为已读
public function readSingle(DatabaseNotification $notification)
{
$this->user()->decrement('notification_count');
$notification->markAsRead();
return $this->response->noContent();
}
测试:
数据库notifications
表:
@hustnzj
加了个判断,不然未读数为0的话会报sql错误。
app\Http\Controllers\Api\NotificationsController.php
还需要确认该通知是否属于user,不然会误操作,需要做个权限判断