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

dmytroshved's avatar

How to return a 404 error on a GET request to a route like /recipes/{id} if the route only exists for DELETE?

I have a route:

Route::delete('/recipes/{recipe}', [RecipeController::class, 'destroy'])->name('recipes.destroy');

but If I am trying to manually write in the uri input /recipes/1 I am getting an error:

The GET method is not supported for route recipes/1. Supported methods: DELETE.

How can I solve this situation? I don't want user see that error if he try to write /recipes/1

0 likes
5 replies
Snapey's avatar

try with APP_ENV set to production

dmytroshved's avatar

I came up with this solution:

Route::get('/recipes/{recipe}', function (){
     abort(404);
});

Niush's avatar
Niush
Best Answer
Level 50

Your solution is fine for single case. But, to cover all scenarios you can do:

Route::fallback(function () {
    abort(404);
});
1 like

Please or to participate in this conversation.