问题
After a couple of conversations on here i'm finally getting somewhere but after the pagintion now works when i got to search?page=2 i get a json array of the logged in user and not page 2 of the results.
Here's my controller:
public function search()
{
$q = Input::get('term');
if($q && $q != ''){
$searchTerms = explode(' ', $q);
$query = DB::table('wc_program');
if(!empty($searchTerms)){
foreach($searchTerms as $term) {
$query->where('JobRef', 'LIKE', '%'. $term .'%');
$query->orwhere('Road', 'LIKE', '%'. $term .'%');
}
}
$results = $query->paginate(10);
return View::make('layouts.results', compact('results'));
}
}
Route: Route::get('/search', 'HomeController@search');
So how can i work around this?
回答1:
You need to append query string to the pagination.
in your controller, pass the query string to the view.
return View::make('layouts.results', compact('results', 'q'));
In your view (results.blade.php):
append the query string to the pagination otherwise in page 2 you will not get any result.
<?php echo $results->appends(array('term' => $q))->links(); ?>
来源:https://stackoverflow.com/questions/20961006/paginate-search-laravel-issue