From d45e486fefb418ab370267e16271cc911e863d2d Mon Sep 17 00:00:00 2001 From: Yurij Finiv Date: Sat, 10 Oct 2026 21:50:31 +0300 Subject: [PATCH 1/2] Always render admin 404 in actual layout with safe fallback --- src/Exceptions/AdminErrorPages.php | 21 ++++++++++++++++++--- tests/Feature/AdminErrorPagesTest.php | 15 ++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Exceptions/AdminErrorPages.php b/src/Exceptions/AdminErrorPages.php index b0f9f4c..56b537e 100644 --- a/src/Exceptions/AdminErrorPages.php +++ b/src/Exceptions/AdminErrorPages.php @@ -27,13 +27,28 @@ public function __invoke(Throwable $exception, Request $request): ?Response } $guard = (string) config('lazy.auth.guard', 'web'); - $useAdminLayout = in_array($status, [403, 404], true) && Auth::guard($guard)->check(); + $useAdminLayout = $status === 404 || ($status === 403 && Auth::guard($guard)->check()); - return response()->view('lazy::errors.page', [ + try { + return response()->view('lazy::errors.page', [ 'status' => $status, 'useAdminLayout' => $useAdminLayout, 'homeUrl' => url('/'.trim((string) config('lazy.admin.route.prefix', 'admin'), '/')), - ], $status, $exception->getHeaders()); + ], $status, $exception->getHeaders()); + } catch (Throwable $renderFailure) { + if (! $useAdminLayout) { + throw $renderFailure; + } + + // A missing admin page must never escalate into a secondary server error. + report($renderFailure); + + return response()->view('lazy::errors.page', [ + 'status' => $status, + 'useAdminLayout' => false, + 'homeUrl' => url('/'.trim((string) config('lazy.admin.route.prefix', 'admin'), '/')), + ], $status, $exception->getHeaders()); + } } private function isAdminRequest(Request $request): bool diff --git a/tests/Feature/AdminErrorPagesTest.php b/tests/Feature/AdminErrorPagesTest.php index b6ba724..0e7abbf 100644 --- a/tests/Feature/AdminErrorPagesTest.php +++ b/tests/Feature/AdminErrorPagesTest.php @@ -42,7 +42,7 @@ it('avoids the admin shell for guest requests and recoverable session errors', function (): void { $renderer = new AdminErrorPages; - foreach ([401, 403, 404, 419, 429, 500, 503] as $status) { + foreach ([401, 403, 419, 429, 500, 503] as $status) { $response = $renderer(new HttpException($status), Request::create('/admin/missing')); expect($response?->getStatusCode())->toBe($status) @@ -50,8 +50,8 @@ } }); -it('uses the actual admin layout for signed-in missing pages', function (): void { - $user = new class extends \\Illuminate\\Foundation\\Auth\\User {}; +it('uses the actual admin layout for missing pages regardless of the authentication flag', function (): void { + $user = new class extends \Illuminate\Foundation\Auth\User {}; $user->id = 123; $this->be($user); @@ -61,3 +61,12 @@ ->and($response?->getContent())->toContain('data-lazy-admin-shell') ->and($response?->getContent())->toContain('Back to dashboard'); }); + + +it('attempts full admin rendering for a guest 404 instead of the standalone template', function (): void { + $renderer = new AdminErrorPages; + $response = $renderer(new HttpException(404), Request::create('/admin/missing')); + + expect($response?->getStatusCode())->toBe(404) + ->and($response?->getContent())->toContain('data-lazy-admin-shell'); +}); From 8e92be400de9adc8176905f8144972777ea04845 Mon Sep 17 00:00:00 2001 From: CrazyBoy49z <3448603+CrazyBoy49z@users.noreply.github.com> Date: Sat, 10 Oct 2026 18:50:48 +0000 Subject: [PATCH 2/2] Fix styling --- src/Exceptions/AdminErrorPages.php | 8 ++++---- tests/Feature/AdminErrorPagesTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Exceptions/AdminErrorPages.php b/src/Exceptions/AdminErrorPages.php index 56b537e..e362173 100644 --- a/src/Exceptions/AdminErrorPages.php +++ b/src/Exceptions/AdminErrorPages.php @@ -3,8 +3,8 @@ namespace Step2dev\LazyAdmin\Exceptions; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Auth; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Throwable; @@ -31,9 +31,9 @@ public function __invoke(Throwable $exception, Request $request): ?Response try { return response()->view('lazy::errors.page', [ - 'status' => $status, - 'useAdminLayout' => $useAdminLayout, - 'homeUrl' => url('/'.trim((string) config('lazy.admin.route.prefix', 'admin'), '/')), + 'status' => $status, + 'useAdminLayout' => $useAdminLayout, + 'homeUrl' => url('/'.trim((string) config('lazy.admin.route.prefix', 'admin'), '/')), ], $status, $exception->getHeaders()); } catch (Throwable $renderFailure) { if (! $useAdminLayout) { diff --git a/tests/Feature/AdminErrorPagesTest.php b/tests/Feature/AdminErrorPagesTest.php index 0e7abbf..e20a8ce 100644 --- a/tests/Feature/AdminErrorPagesTest.php +++ b/tests/Feature/AdminErrorPagesTest.php @@ -1,5 +1,6 @@ id = 123; $this->be($user); @@ -62,7 +63,6 @@ ->and($response?->getContent())->toContain('Back to dashboard'); }); - it('attempts full admin rendering for a guest 404 instead of the standalone template', function (): void { $renderer = new AdminErrorPages; $response = $renderer(new HttpException(404), Request::create('/admin/missing'));