the_unforgiven_II
the_unforgiven_II

Reputation: 361

Paginate search result laravel

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
 }
}

Upvotes: 1

Views: 2955

Answers (1)

Andreyco
Andreyco

Reputation: 22862

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

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

Upvotes: 2

Related Questions