I'm using laravel version 9.x, where I can handle exception in App\Exceptions\Handler.php
file like below
public function register()
{
$this->renderable(function (NotFoundHttpException $e, $request) {
return redirect(route('home'));
});
}
But problem is as a requirement I have to redirect all exception (not only NotFoundHttpException) or error to home page when application debug mode is false.
How can I redirect all error or exception to home page ?
CodePudding user response:
To redirect all exceptions to the home page, you can use a catch-all exception handler in the renderable method like this
public function register()
{
$this->renderable(function (\Exception $e, $request) {
return redirect(route('home'));
});
}
This will catch all exceptions and redirect them to the home page