Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mahesh's avatar

MethodNotAllowedHttpException

I am trying to create a form and send the data to a route and just display the user name. My View is

{!! Form::open(['url'=>'login/check','method'=>'PATCH']) !!}
User Name : {!! Form::text('user')!!}<br>
Password : {!! Form::text('password')!!}
{!! Form::submit('Login')!!}
{!! Form::close() !!}

My Route is

Route::get('login/check','Login@create');

I have a function in Login controller as

    public function create()
    {
    return 'hello'; 
    }

I am getting MethodNotAllowedHttpException in RouteCollection.php line 207: What would have gone wrong.

0 likes
9 replies
graham's avatar

What's on line 207 of RouteCollection.php?

Mahesh's avatar

@Graham :

on 207 of RouteCollection.php its just

throw new MethodNotAllowedHttpException($others);

in RouteCollection.php line 207 at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 194 at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 142 at RouteCollection->match(object(Request)) in Router.php line 719 at Router->findRoute(object(Request)) in Router.php line 642

graham's avatar

Sorry @Mahesh I was half asleep :)

Just as an experiment, change the route to accept any verb:

Route::any('login/check','Login@create');

then try:

Route::patch('login/check','Login@create');
Mahesh's avatar

@Graham : Its working. But how does that create a problem with get. Since Route::get works for all the routes. Educate me on this plz

graham's avatar

You've set a patch verb in your view so it's submitting a patch request.

1 like
bashy's avatar
bashy
Best Answer
Level 65
  • Route::get() will respond to GET requests.
  • Route::post() will respond to POST requests.
  • Route::delete() will respond to DELETE requests (this includes when adding the custom DELETE
  • Route::put() will respond to PUT requests (this includes when adding the custom PUT
  • Route::patch() will respond to PATCH requests (this includes when adding the custom PATCH

You should use patch() for HTML forms, you add method = PATCH and it will pick it up with the hidden form field (_method I believe)

HTML forms CANNOT send PATCH requests, pick them up with

Route::patch()
3 likes
graham's avatar

@bashy shouldn't an update use a patch request? I notice that's what's being used here too:

https://www.flynsarmy.com/2015/02/creating-a-basic-todo-application-in-laravel-5-part-1/ https://www.flynsarmy.com/2015/02/creating-a-basic-todo-application-in-laravel-5-part-3/

I understand a browser can't submit a patch request but my understanding is the patch is faked by setting the method.

Sorry for digressing, I'm trying to get this straight in my own head. From the look of the opening post from @Mahesh the patch verb probably isn't the right one to use in this case anyway.

bashy's avatar

@Graham Maybe Route::patch does work for HTTP forms since the framework finds that route from the hidden field _method? I always use resource so I've never had to write them out manually.

graham's avatar

@bashy PATCH wasn't mentioned in the method spoofing documentation until now:

HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form.

The value sent with the _method field will be used as the HTTP request method. https://github.com/laravel/docs/blob/5.0/routing.md#method-spoofing

Please or to participate in this conversation.