Reputation: 57
I have a question: how I redirect in Laravel from a 404 error to a route???
This is the route: Route::get("/errorpage","Controller@errorpage")->name("errorpage");
Upvotes: 1
Views: 1304
Reputation: 484
For that, you need to do add few lines of code to render method in app/Exceptions/Handler.php file which looks like this:
public function render($request, Exception $e)
{
if($this->isHttpException($e))
{
switch ($e->getStatusCode())
{
// not found
case 404:
return redirect()->guest('/errorpage');
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $e);
}
}
Upvotes: 1