How can I redirect all 404 errors to homepage? I have custom Error Page but google analytics is throwing too much errors.
For that, you need to do add few lines of code to render
method in app/Exceptions/Handler.php
file.
public function render($request, Exception $e)
{
if($this->isHttpException($e))
{
switch (intval($e->getStatusCode())) {
// not found
case 404:
return redirect()->route('home');
break;
// internal error
case 500:
return \Response::view('custom.500',array(),500);
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $e);
}
}