Support the ongoing development of Laravel.io →
Laravel
0

Technically there is a difference between a not found (with a status code 404) and a not allowed (with a status code 405)

Laravel give you a lot of options for handling exceptions.

An option that can be useful for you is Rendering Exceptions

use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
 
/**
 * Register the exception handling callbacks for the application.
 *
 * @return void
 */
public function register()
{
    // This will throw a 404 / not found exception if we try to render a MethodNotAllowedHttpException (like if we do a GET on a POST url.
    $this->renderable(function (MethodNotAllowedHttpException $e, $request) {
        abort(404);
    });
}
1

Sign in to participate in this thread!

Cloudways

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.