I create a Laravel 5 web application and had confronted with some difficulties with sorting and searching.
I have a table with some companies, which I get from a database. This table has several columns: Name, Industry, Country, etc. Table is sortable by clicking on the column header.
The Route for sorting is:
Route::get('/{sort?}/{order?}', 'CompaniesController@index')
->where('sort', 'id|name|country')
->where('order', 'asc|desc')
->name('companies');
Also I use simplePaginate() for paginating output results.
Url for the first page looks like:
http://ift.tt/2hhepVo or http://ift.tt/2gS2Cjr
and with pagination looks like http://ift.tt/2hhgRLN
By this moment everything is working properly. But I also want to use HTML form for search by name, country, etc.
I tried to pass current url to action parameter and got this after submitting a form:
http://ift.tt/2gS0tEB.
I can work with this parameters and use them, but if I go to the second page using pagination I lost query string. I undestood that this way is wrong.
Next I tried to use Search Route:
Route::get('/search',['uses' => 'SearchController@getSearch','as' => 'search']);
with SearchController but I don't know how realise it properly.
I need combined usage of searching, sorting and pagination but I don't know how to include search parameters into the url for proper usage.
Thanx for helping.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire