如何像Twitter一样对通知进行分组?

时间:2020-02-28 00:59:52

标签: laravel nuxt.js

我有laravel后端和nuxtjs前端。我想显示诸如Twitter之类的通知。

如果有5个人喜欢,我会收到5则相同的通知...然后我想显示“在X帖子上有5个人喜欢”。

我试图通过groupBy('post')对其进行分组,但这是行不通的。

我的通知界面;

Nuxtjs

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);
    }

和我的数据库结构:

Database Structure

0 个答案:

没有答案
相关问题