#405 (Method not allowed) instead of 404?

9 messages · Page 1 of 1 (latest)

cyan cloak
#

Hey, newbie here. Why am I getting error 405 Method not allowed for route that was not defined? I expected to see error 404, right?
Tried to access route "tasks/{task}" with **get **request, but these are my routes and the one I tried isn't defined here.

Route::name('tasks.')->group(function () {
   Route::middleware(['auth', 'verified'])->group(function () {
      Route::controller(TaskController::class)->group(function () {
          Route::get('/tasks', 'index')->name('index');
          Route::post('/tasks', 'store')->name('store');
          Route::patch('/tasks/{task}', 'finish')->name('finish');
      });
   });
});

With debug on, I get the message "The GET method is not supported for route tasks/44845. Supported methods: PATCH." and yeah that's true, but should it show 404 then?

proud cliff
#

well there is a /task/{task} route, right?

#

it looks at the routes and sees there is this route but with PATCH method hence when you try GET, you receive method not supported.

cyan cloak
#

yeah, maybe this is correct behavior, I'm very new to laravel, I just expected different outcome from this

proud cliff
#

it's not about laravel
it's http convention
that's 404 and 405

#

A 404 tells you that the requested URL couldn't be found or that it was entered incorrectly. A 405 error message, on the other hand, confirms that the requested page does exist (and the URL was input correctly), but an unacceptable HTTP method was used to make the initial request.

cyan cloak
#

That makes sense to me now, thank you! 🙂

proud cliff
#

yw buddy
if it's solved you can add solved tag