分页查询bug
关于分页的一个bug。网上也找到一段类似的,还请各位大大能给出个解决方案:
$query = DB::table('vendor_profiles');
if (Input::has('subcat_id') AND Input::get('subcat_id') > 0) {
$query->join('vendor_subcat_rel', function($join) {
$join->on('vendor_profiles.user_id', '=', 'vendor_subcat_rel.vendor_id')
->where('vendor_subcat_rel.subcat_id', '=', Input::get('subcat_id'));
});
}
$query->orderBy($sort, $order);
$vendors = $query->paginate(2);
结果:
When I return $vendors i get:
{"total":2,"per_page":1,"current_page":1,"last_page":2,"from":1,"to":1,"data":[]}
I am not getting any data. But if i do $query->get(); i get the results. What is wrong with my code? paginate() is giving the problem. It works if i remove join condition.
说明:
使用paginate后拿不到data数据,但用get是能获取数据的。
paginate是能获取到数据总数的,但拿不到数据。
下图是我paginate查询的打印的结果。加粗文字
问题就出在join on后面加了where条件
有大神能解决下?
$query = DB::table('vendor_profiles');
if (Input::has('subcat_id') AND Input::get('subcat_id') > 0) {
$query->join('vendor_subcat_rel', function($join) {
$join->on('vendor_profiles.user_id', '=', 'vendor_subcat_rel.vendor_id')
->where('vendor_subcat_rel.subcat_id', '=', Input::get('subcat_id'));
});
}
$query->orderBy($sort, $order);
$vendors = $query->paginate(2);
结果:
When I return $vendors i get:
{"total":2,"per_page":1,"current_page":1,"last_page":2,"from":1,"to":1,"data":[]}
I am not getting any data. But if i do $query->get(); i get the results. What is wrong with my code? paginate() is giving the problem. It works if i remove join condition.
说明:
使用paginate后拿不到data数据,但用get是能获取数据的。
paginate是能获取到数据总数的,但拿不到数据。
下图是我paginate查询的打印的结果。加粗文字
问题就出在join on后面加了where条件
有大神能解决下?
0 个回复