Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

How can I hide MethodNotAllowedHttpException on laravel

When we try to access url with an undefined method in laravel we get an exception of MethodNotAllowedHttpException.

If a route with POST request is called via GET request it will give us this exception.

What is the standard way of hiding this scary exception on laravel?

enter image description here

Upvotes: 0

Views: 903

Answers (3)

jeanj
jeanj

Reputation: 2166

In your config file set Debug to false in production. When debug is set to false it will display the default error page Hmm.. Something went wrong....

You can make custom error pages, check the documentation here

Upvotes: 1

George Sharvadze
George Sharvadze

Reputation: 570

One way is to disable Debug option, or you can use Exception Handler to display an error page

Upvotes: 1

thefallen
thefallen

Reputation: 9749

You can listen for any exception in App\Exceptions\Handler@render:

    if ($e instanceof MethodNotAllowedHttpException) {
        return response()->view('errors.404', [], 404);
    }

And then render whatever view you want to tell the user what is happening.

Upvotes: 2

Related Questions