Laravel Pagination causes MethodNotAllowedHttpException ?

Posted 6 months ago by uccdev

So I am working on a site that paginates two different types of DB queries.

The first is a generic "get everything" query. The second has specific checks (e.g "WHERE name = 'John'")

Both are done with simplePaginate(num); I'll show my code if it's considered relevant.

The first works perfectly fine. BUT the second throws an error whenever I use the Next or Previous buttons to fetch the next results.

               Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

No message

This is not an out-of-bounds error since I know the database has more values under the specified query. **EDIT: No longer the case, see "EDIT 2". **

Does anyone know why this happens?

EDIT: For clarity, here is my code for the second query. It works for the first page, but ONLY causes errors when I use one of the buttons to move to another page.

          $postmen = DB::table('postmen')
  ->join('cats', 'postmen.cat_id', '=', 'cats.cat_id')
  ->join('reg_status', 'postmen.status_id', '=', 'reg_status.status_id')
  ->select('postmen.postmen_id', 'postmen.forename', 'postmen.surname',
   'cats.description AS catdesc', 'reg_status.description AS regdesc')
   ->where(function ($query) use ($request) {
     if (!empty($request->forename)) {
       $query->where('postmen.forename', $request->forename);
     if (!empty($request->surname)) {
       $query->where('postmen.surname', $request->surname);
     if (!empty($request->cat_id)) {
       $query->where('postmen.cat_id', $request->cat_id);
     if (!empty($request->status_id)) {
       $query->where('postmen.status_id', $request->status_id);
     if (!empty($request->postmen_id)) {
       $query->where('postmen.postmen_id', $request->postmen_id);

EDIT 2: It's been pointed out that now the route was incorrect. I had been using exclusively "route::post". I have added a route::get for my view now:

      Route::get('/postmen', '[email protected]');

I am no longer getting a "MethodNotAllowedHttpException". Instead I am getting a time-out because it's redirecting itself too often. I'm not sure what's wrong there.

Any advice?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.