I would like to show 404 page in Laravel 5 while MethodNotAllowedHttpException
throws.
Can anyone help me in this regard?
I would like to show 404 page in Laravel 5 while MethodNotAllowedHttpException
throws.
Can anyone help me in this regard?
Add this to app/Exceptions/Handler.php
:
public function render($request, Exception $e)
{
if ($e instanceof MethodNotAllowedHttpException)
{
abort(404);
}
return parent::render($request, $e);
}
Then edit resource/views/errors/404.blade.php
to personalize the page.
Simple: all you have to do is create a template at resources/views/errors/404.blade.php.
You can create views for other HTTP status codes if you’re feeling that way inclined, such as a 403.blade.php for Forbidden exceptions and so on.
I'm working on Laravel 5.2 and the answer given here worked for me.
You need to modify the render method in the app/Exceptions/Handler.php.
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException)
{
return response(view('errors.404'), 404);
}
return parent::render($request, $e);
}
abort(404)
did not work for me. Looks like this method is removed in Laravel 5.
That's a 405 error, easiest way would be to create a new view in resources/views/errors/405.blade.php.
.
If you need fine control over what is displayed then you'll have to use the Handler.php to modify what's returned.