1$user_info = DB::table('usermetas')
2 ->select('browser', DB::raw('count(*) as total'))
3 ->groupBy('browser')
4 ->get();
1You can use unique('field_name'); instead of groupBy('field_name');
2/**
3 * Show the application dashboard.
4 *
5 * @return \Illuminate\Http\Response
6 */
7public function index()
8{
9 $messages = Message::select("*")
10 ->where('receiver_id',$id)
11 ->orderBy('created_at', 'desc')
12 ->get()
13 ->unique('sender_id');
14
15 dd($messages);
16}
1//If You want the latest id of records then you can use unique() after get(),
2//don't use group by if you use groupBy
3//then you lose your control from id. I hope this is useful for you
4
5myModel::select('id','purch','name','prcvalue')
6 ->where('purch','=','10234')
7 ->orderBy('prcvalue','DESC')
8 ->get()
9 ->unique('name');
10