Question

[Solved] MethodNotAllowedHttpException in RouteCollection.php line 218:4

I will get MethodNotAllowedHttpException when submitting a form in laravel

Html file

<form method="POST" action="/cards/{{$card->id}}/notes">
    <input name="_token" type="hidden" value="{{ csrf_token() }}"/>
    <textarea name="body" class="form-control"></textarea>
    <button type="submit">Add Note</button>
</form>

routes.php

Route::post('cards/{card}/notes','[email protected]');

NotesController.php

namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;

class NotesController extends Controller
{
    public function store()
    {
        return request()->all();
    }
}
Enquirer: Asim

||

Solution #1:

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}', '[email protected]');
Route::post('cards/{card}/notes', '[email protected]');

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.

Respondent: Pistachio

Solution #2:

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','[email protected]');
  1. Add the parameter to your controller:
    public function store($card)
    {
        return request()->all();
    }
Respondent: Gras Double

Solution #3:

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

Respondent: Black Mamba

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy