how to use groupby in laravel 8 code example
Example: groupby in laravel
You can use unique('field_name'); instead of groupBy('field_name');
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$messages = Message::select("*")
->where('receiver_id',$id)
->orderBy('created_at', 'desc')
->get()
->unique('sender_id');
dd($messages);
}