Show 404 Page in Laravel 5
I would like to show 404 pages 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 in resources / views / errors / 404.blade.php .
You can create views for other HTTP status codes if you feel like it's oblique, like 403.blade.php for Forbidden exceptions, etc.
I am working on Laravel 5.2 and the answer I got here worked for me.
You need to change the render method in 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)
didn't work for me. It looks like this method has been removed in Laravel 5.
That there is a 405 error, the easiest way is to create a new view in resources/views/errors/405.blade.php.
.
If you want precise control over what is displayed, you will have to use Handler.php to change the return value.