$user_info = DB::table('usermetas')
->select('browser', DB::raw('count(*) as total'))
->groupBy('browser')
->get();
$groupedSalesCampaign = Order::with('Campaign')
->where('isapproved','=','Y')
->groupBy('campaign_id')
->orderBy(DB::raw('COUNT(id)','desc'))
->get(array(DB::raw('COUNT(id) as totalsales'),'campaign_id'));
User::where('username','john doe')
->where(function($query)
{
$query->where('age','>',30)
->orWhere('email','=','johndoe@xyz.com');
})
->toSql();
//If You want the latest id of records then you can use unique() after get(),
//don't use group by if you use groupBy
//then you lose your control from id. I hope this is useful for you
myModel::select('id','purch','name','prcvalue')
->where('purch','=','10234')
->orderBy('prcvalue','DESC')
->get()
->unique('name');