我有以下ORM
$trucksobj = DB::Table('trucks')
->orderBy('trucks.id','desc')
->join('trucktypes', 'trucks.trucktype_id', '=', 'trucktypes.id');
if($overweight=="on")
$trucksobj->where('trucktypes.max_weight', '>', 'trucks.weight');
$trucks=$trucksobj->get();
它就像一个魅力,但是当我用get()
替换paginate()
时,它没有响应,即
$trucks=$trucksobj->paginate(5);
无效?
我错过了什么?
答案 0 :(得分:0)
请遵循:http://culttt.com/2014/02/24/working-pagination-laravel-4/
使用手动查询时请使用分页器功能:
$trucksobj = DB::Table('trucks')
->orderBy('trucks.id','desc')
->join('trucktypes', 'trucks.trucktype_id', '=', 'trucktypes.id');
if($overweight=="on")
$trucksobj->where('trucktypes.max_weight', '>', 'trucks.weight');
$trucks=$trucksobj->get();
//$paginator = Paginator::make($items, $totalItems, $perPage);
$paginator = Paginator::make($trucks, count($trucks), 5);
答案 1 :(得分:0)
public function pagination()
{
$users = DB::table('img')
->join('category', 'category.id', '=', 'img.category_id')
->select('img.category_id', 'category.name', 'img.img_url')
->paginate(2);
return view('page', compact('users'));
}