Answer the question
In order to leave comments, you need to log in
Laravel 4 pagination when searching?
Good day. The bottom line is this - I make a get request to the controller, which finds the products I need with a like (LIKE) and displays them with pagination, but when I go to page 2, 3, etc. , then the ?search parameter becomes empty (was /search?search="some query" , became /search?page=3 ). How to implement the url /search?search="request"&page=3 , or /search/request/3 , if it is easier to implement? Otherwise, on the first page, the products taken from the search are displayed, and on the next - just all the products ... If I don't explain myself clearly, I'm sorry :)
Rout
Route::get('store/search', array('uses'=>'[email protected]'));
public function getSearch()
{
$search = Input::get('search');
return View::make('store.index')
->with('products', Product::where('title', 'LIKE', '%'.$search.'%')->paginate(3))
->with('search', $search);
}
<div class="search_box pull-right">
{{ Form::open(array('url'=>'store/search', 'method'=>'get')) }}
{{ Form::text('search', null, array('placeholder'=>'Поиск')) }}
{{ Form::submit('Поиск', array('class'=>'')) }}
{{ Form::close() }}
</div>
@section('pagination')
<div id="pagin">
{{ $products->links() }}
</div>
@stop
Answer the question
In order to leave comments, you need to log in
appends(string $key, string $value = null)
laravel.com/api/4.2/Illuminate/Pagination/Paginato...
Here's the method you need, try it, if it doesn't fit, there are a couple more interesting methods, like
addQuery(string $key, string $value)
{{ $products->appends(array('search' => $search))->links() }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question