mashadov40 mashadov40 - 1 year ago 210
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">

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.


Answer Source

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">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download