How can i get the latest 8 votes on this query by mobile number field:
results = DB::table('votes')->whereIn('votes.id', function($query){
$query->select(DB::raw('MAX(id) as id'))
->from('votes')
->groupBy('mobile_number', 'position_id','code');
})->where(array('code'=>$code,'position_id'=>$positionId))->get();
on this query it gets the latest total votes of the users but not limited to 8.
->where(array('code'=>$code,'position_id'=>$positionId))->take(8)->get(); //it seems this is not working
here's the sample table
id mobile_number code position_id
1 123123 1 1
2 123123 1 1
3 321212 2 2
4 123123 1 1
5 123123 1 1
6 123123 1 1
7 123123 1 1
8 123123 1 1
9 123123 1 1
10 123123 1 1
if i get the votes of 123123 it will get only the latest 8 so on the above table the Id 1 will not be included in the results.
Any idea? Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire