Support the ongoing development of Laravel.io →
posted 2 years ago
Laravel
0
moderator

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);
    });
}

faisal liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.