From 46217133e6c1d189f0a08d86065feccbba07e502 Mon Sep 17 00:00:00 2001 From: Frank John Begornia Date: Mon, 20 Apr 2026 03:21:31 +0800 Subject: [PATCH] feat: add custom 404 error page and handle exceptions for not found errors --- app/Exceptions/Handler.php | 7 +++ resources/views/errors/404.blade.php | 91 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 resources/views/errors/404.blade.php diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index fd662eb..1359da1 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -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); } diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php new file mode 100644 index 0000000..4099f5a --- /dev/null +++ b/resources/views/errors/404.blade.php @@ -0,0 +1,91 @@ + + + + + 404 | Page Not Found + + + +
+
+
404
+
Page Not Found
+
The page you are looking for does not exist or may have been moved.
+ +
+
+ + -- 2.49.1