1
votes

I have a form and i am trying to update the forms. In the form, 'name' is a unique field (added the unique condition in request page and in a table, name is set as unique). when i try to update the form (i provided the value, the is already exist in the table), it shows 'MethodNotAllowedHttpException in RouteCollection.php line 219' error.

If i am update the 'name' with non-existing name that is not in table, it will work without any issues.

Error

Router

Route::group(['middleware' => ['superadmin']], function () {
    Route::post('/sadmin/update_club',array('uses' => 'SAdmin\ClubController@updateClub', 'as' => 'updateClub'));
}

Request

class UpdateClubRequest extends Request
{    
   public function authorize()
   {
      return true;
   }
   public function rules()
   {
     return [
        'name' => 'required|max:150|unique:clubs,name,'.Request::input('id'),
        'logo' => 'image|mimes:jpeg,png,bmp,gif,svg|max:10000',
      ];
   }
 }

Layout Page

{{ Form::open(array('route' => 'updateClub', 'method' => 'POST', 'class' => 'form-horizontal', 'files'=>true)) }}

  {{ Form::hidden('id', $club[0]['id']) }}
  {{ Form::text('name', $club[0]['name'], array('class' => 'form-control', 'maxlength' => 50)) }}

{{ Form::close() }}   
1
I feel MethodNotAllowedHttpException is typically related to posting to a get route or vice versa, which is what the error message shows as well. By chance do you have a get route defined to the same location above your post route?camelCase
@camelCase . yes i have lot of get route... Route::get('/sadmin/clubs', 'SAdmin\ClubController@Clubs'); Route::get('/sadmin/add_club', 'SAdmin\ClubController@addClub');Lindo Sebastian
But any to '/sadmin/update_club'?camelCase

1 Answers

2
votes

I don't see any error here so it's possible error might be somewhere else. I see for example that you are using superadmin for this route. You should run in console:

php artisan route:list

to see what middlewares are applied to updateClub route name and verify this middlewares code because it's possible that some of them is making incorrect redirection (method GET to route that has only POST for example).

The second thing (it's not causing problem here but you should follow some standards) - if you create action that updates something, you should use PUT method (POST is for creating new objects), so in both route and form for this route you should change POST into PUT

EDIT

The problem could be also a bit different. Let's assume you have multi-step form (probably this is your case because you are using POST only for , so you are using the following methods GET (step1) -> POST (step2) -> POST (step3). So now, if in step2 you get error, Request class will try to make redirection again to step2 but with GET method, so you should in routes.php allow also GET method, so in your case you should probably change

Route::post('someroute' ...

into:

Route::match(['get','post'], 'someroute' ...

You should do it for page for which you are displaying this form