group by laravel
snippet in php

group by laravel

user3319

$user_info = DB::table('usermetas')
                 ->select('browser', DB::raw('count(*) as total'))
                 ->groupBy('browser')
                 ->get();

groupby in laravel

user749

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

laravel db::query update

user3326

 DB::table('user')->where('email', $userEmail)->update(array('member_type' => $plan));