2015-11-02 67 views
1

我怎样才能在此查询最新的8票通过手机号码字段:获得最新的8条laravel 5.1

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

此查询它获取用户的最新总票数但不限于:8 。

->where(array('code'=>$code,'position_id'=>$positionId))->take(8)->get(); //it seems this is not working 

这里的样品台

id mobile_number code position_id 
1 123123   1  1 
2 123123   3  1 
3 321212   2  2 
4 123123   4  1 
5 123123   5  1 
6 123123   6  1 
7 123123   7  1 
8 123123   8  1 
9 123123   9  1 
10 123123   10  1 

,如果我得到的123123票,将只能得到最新8等上表中的Id 1将不会包含在结果中。

有什么想法?由于

+0

如果我是你,我会看口才它将使查询非常容易:-) – Anoxy

回答

0

试试这个

对于年长版本

take(8)->skip(8)->get(); 

对于版本

limit(8)->offset(8)->get(); 
+0

其没有得到结果 – Cris

+0

不能测量? –

+0

试着用这个'orderBy(?Query?) - > take(5) - > get()' –