MethodNotAllowedHttpException in RouteCollection.php line 218:4

后端 未结 3 1691
灰色年华
灰色年华 2021-01-22 06:52

I will get MethodNotAllowedHttpException when submitting a form in laravel

Html file

id}}/notes\"&g
相关标签:
3条回答
  • 2021-01-22 07:22

    MethodNotAllowedHttpException is thrown when no matching route (method and URI) was found, but a route with a matching URI but not matching method was found.

    In your case, I guess the issue is because URI parameters differ between the route and the controller.

    Here are two alternatives you can try:

    1. Remove the parameter from your route:
    Route::post('cards/notes','NotesController@store');
    
    1. Add the parameter to your controller:
        public function store($card)
        {
            return request()->all();
        }
    
    0 讨论(0)
  • 2021-01-22 07:29

    Make sure you don't have a route, say a Route::post with a parameter that lies in front of the route you are trying to hit.

    For example:

    Route::post('{something}', 'SomethingController@index');
    Route::post('cards/{card}/notes', 'NotesController@store');
    

    In this case, no matter what you try to send to the cards route, it will always hit the something route because {something} is intercepting cards as a valid parameter and triggers the SomethingController. Put the something route below the cards route and it should work.

    0 讨论(0)
  • 2021-01-22 07:40

    I have tried to solve this error in lumen and it took me quite a lot of time to figure out the problem. The problem is with laravel itself.

    Sometimes if you have another route like GET device/{variable}, laravel stops in this first route...

    So what you need to do is change the route POST device to POST device/add

    This link helped me a lot

    0 讨论(0)
提交回复
热议问题