mashadov40 mashadov40 - 1 month ago 20
PHP Question

Laravel 5.3 MethodNotAllowedHttpException in RouteCollection.php when try to post

In my routes/web.php file

Route::get('/users', [
'uses' => 'Admin\UsersController@Index',
'as' => 'users'
]);
Route::post('/adduser', [
'uses' => 'Admin\UsersController@Create',
'as' => 'adduser'
]);


This is my index.blade.php

<form action="{{route('adduser')}}" class="form-horizontal" method="post">
{!! csrf_field() !!}
<input name="_method" type="hidden" value="PATCH">
<div class="form-body">
<div class="form-group">
<label class="col-md-3 control-label">User Name</label>
<div class="col-md-4">
<input type="text" id="name" class="form-control input-circle" placeholder="Kullanıcı Adını Yazınız">
</div>
</div>


When i try to post this or another submit form, I got an error which says "MethodNotAllowedHttpException in RouteCollection.php line 218". I would appreciate any help to solve this error. Hope you guys help me.

Regards.

Answer

You should change route to push to make it work:

Route::push('/adduser', [
    'uses' => 'Admin\UsersController@Create',
    'as' => 'adduser'
]);

Or change _method to POST:

<input name="_method" type="hidden" value="POST">
Comments