Answers for "group by and order by not working together in laravel"

PHP
1

how to use groupby and orderby together 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);
}
Posted by: Guest on December-21-2020

Code answers related to "group by and order by not working together in laravel"

Browse Popular Code Answers by Language