default pagination with searching i want to use search with default pagination method.
the problem is that default paginate method is get
and when i implement search i have to make it post
after that if i click on next page it gives method not allowed exception.
my controller code is as below
public function getproductListData(Request $request) {
$input = $request->all();
$filter = $input['filter'];
$products = Product::where('name', 'like', '%' . $input['filter'] . '%')->paginate(9);
return view('front.product.product-list1', compact('products','filter'));
}
route
Route::post('/cartProductList', 'ProductController@getproductListData')->name('product.filter');
Add oldest and get your page as like below.
$products = Product::where('name', 'like', '%' . $input['filter'] . '%')->oldest()->paginate(9);
Fastest way to fix that, will be to use "get" instead of post.
Or you may use:
Route::match(['get', 'post'], '/', function () {
//
});
@munazzil what is use of oldest() i don't understand
It is retrieving your data from database beginning to the end.have it got worked?
The point is, when you press next page button, your route is accessed via "GET" method, while your route use "POST" method, so I wrote above how you can fix it.
See https://drive.google.com/file/d/0B1_PFw--3o74YjVreHNBOWU2aEE/view
search form
is submit set
yes, first round derived from post
no, continued with get request and querystring
You have to append the querystring parameters to pagination.
Taylor covers it in the docs.
And fyi search and pagination has been covered.
So my QS looks like
http://whatever_site/dog/indexadmin?p=2&psch=c&aval=n
the
&psch=c&aval=n
is what's appended to querystring.
You could have also a separate search form.
Please sign in or create an account to participate in this conversation.