Paginate search result laravel

你说的曾经没有我的故事 提交于 2019-12-24 14:28:14

问题


After some help in a previous post Laravel - Search Facility on site using Eloquent I now need to some help on paginating the result using the built in laravel pagination class.

public function search()  //no parameter now
{
 $q = Input::get('term');
 if($q && $q != ''){
  $searchTerms = explode(' ', $q);
  $query = DB::table('wc_program');  // it's DB::table(), not DB::tables

if(!empty($searchTerms)){

  foreach($searchTerms as $term) {
    $query->where('JobRef', 'LIKE', '%'. $term .'%');
  }
}
$results = $query->get();

dd($results); // for debugging purpose. Use a View here
 }
}

回答1:


Simply change get to paginate and provide number of items per page.

$results = $query->paginate(10);


来源:https://stackoverflow.com/questions/20960564/paginate-search-result-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!