2017-01-21 16:05
浏览 138

Laravel 5.3 API分页

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

so for i did this

//search Drivers
public function getSearchList($limit) 
    $drivers = Driver::paginate($limit)
               ->orderBy('first_name', 'asc')

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

but i'm getting error on requesting 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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanjumie8753 2017-01-21 16:08

    You should use paginate() method instead of get():

    $drivers = Driver::select('id', 'first_name', 'last_name', 'phone_number', 'registration_id')
               ->orderBy('first_name', 'asc')
    打赏 评论
  • duanduan1993 2017-01-21 16:10
    $drivers = Driver::
               ->orderBy('first_name', 'asc')

    Delete ; after paginate($limit)


    打赏 评论

相关推荐 更多相似问题