我有laravel后端和nuxtjs前端。我想显示诸如Twitter之类的通知。
如果有5个人喜欢,我会收到5则相同的通知...然后我想显示“在X帖子上有5个人喜欢”。
我试图通过groupBy('post')对其进行分组,但这是行不通的。
我的通知界面;
Laravel代码:
public function showNotifications(Request $request)
{
$nuser = request()->user();
$notifications = Notification::where('reciever', $nuser->id)
->whereNotIn('sender', [$nuser->id])
->with('sender', 'reciever', 'post', 'game')
->orderBy('created_at', 'DESC')
->paginate(10);
return response()->json($notifications);
}
和我的数据库结构: