feat: add custom 404 error page and handle exceptions for not found errors

This commit is contained in:
Frank John Begornia
2026-04-20 03:21:31 +08:00
parent e479cf41e4
commit 46217133e6
2 changed files with 98 additions and 0 deletions

View File

@@ -2,6 +2,8 @@
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler {
@@ -42,6 +44,11 @@ class Handler extends ExceptionHandler {
if (!$e instanceof Exception) {
$e = new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}
if ($e instanceof NotFoundHttpException || $e instanceof ModelNotFoundException) {
return response()->view('errors.404', [], 404);
}
return parent::render($request, $e);
}