Laravel 的分页

$per_page = $request->input("per_page", 20);

$users = DB::table('users')->paginate(15);
# 或者
$users = App\User::where('votes', '>', 100)->paginate($per_page);

foreach($users as $user){}
{
   "total": 50,
   "per_page": 15,
   "current_page": 1,
   "last_page": 4,
   "first_page_url": "http://laravel.app?page=1",
   "last_page_url": "http://laravel.app?page=4",
   "next_page_url": "http://laravel.app?page=2",
   "prev_page_url": null,
   "path": "http://laravel.app",
   "from": 1,
   "to": 15,
   "data":[
        {
            // 结果对象集
        },
        {
            // 结果对象集
        }
   ]
}

你可能感兴趣的:(phplavarel)