如何创建收件箱?我找不到答案。
public function inbox()
{
$user = Auth::user();
$messages = Message::where('sender_id', '=', $user->id)
->orWhere('receiver_id', '=', $user->id)
->orderBy('created_at', 'desc')
->get(['sender_id', 'message', 'created_at'])
->groupBy('sender_id');
}
我的桌子:
id | sender_id | receiver_id | message | created_at | updated_at
如果我发送一条消息,在列表中显示我的姓名,而不是姓名。
答案 0 :(得分:0)
尝试一下,添加Latest()方法
public function inbox()
{
$user = Auth::user();
$messages = Message::where('sender_id', '=', $user->id)
->orWhere('receiver_id', '=', $user->id)
->orderBy('created_at', 'desc')
->get(['sender_id', 'message', 'created_at'])
->groupBy('sender_id')
->latest()
->get();
}