简体   繁体   English

Laravel 5.3 API 分页

[英]Laravel 5.3 API Pagination

i'm working on an API, and i'm stuck at pagination first i should send only first 10 records later based on the limit value passed by user i should send the next 10 records我正在开发一个 API,我首先被困在分页上 我应该根据用户传递的限制值只发送前 10 条记录 我应该发送next 10 条记录

so for i did this所以因为我做了这个

//search Drivers
public function getSearchList($limit) 
{
    //dd($limit);
    $drivers = Driver::paginate($limit)
               ->select('id','first_name','last_name','phone_number','registration_id')
               ->orderBy('first_name', 'asc')
               ->get();

    return Response::json([
        'data' => $drivers->all()
    ]);
}

but i'm getting error on requesting http://localhost:8000/api/v1/search-list/10但我在请求http://localhost:8000/api/v1/search-list/10出错

BadMethodCallException in Macroable.php line 74:
Method select does not exist.

i thing i'm not doing it right我的事情我做错了

looking forward for much needed help期待得到急需的帮助

thank you谢谢你

You should use paginate() method instead of get() :您应该使用paginate()方法而不是get()

$drivers = Driver::select('id', 'first_name', 'last_name', 'phone_number', 'registration_id')
           ->orderBy('first_name', 'asc')
           ->paginate($limit);
$drivers = Driver::
          select('id','first_name','last_name','phone_number','registration_id')
           ->orderBy('first_name', 'asc')
           ->paginate($limit);

Delete ;删除; after paginate($limit) paginate($limit)paginate($limit)

https://laravel.com/docs/5.3/pagination https://laravel.com/docs/5.3/pagination

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM