Tricks

自定义 Laravel 错误页面

Jun 17, 2023
Martin

如果你使用 Admin Panel 创建 SAAS 或者其他的站点,你可能花费额外的精力区使用自定义主题和品牌。本文将向你展示在 Laravel 错误页中扩展品牌是何其简单:

首先,使用 php artisan vendor:publish --tag=laravel-errors 发布 Laravel 错误页面。

resources/views/errors 中定位发布的 Blade 文件。在每个视图文件中,将内容替换为404.blade.php的以下示例:

<x-filament::layouts.card title="Error 404" class="text-center">
<p>Oops! This resource does not exist. Contact support if this problem persists.</p>
<x-filament::button tag="a" href="{{ route('filament.pages.dashboard') }}">Back to Dashboard</x-filament::button>
{{-- {{ $exception->getMessage() }} --}}
</x-filament::layouts.card>

请注意已注释的 $exception->getMessage()。一些错误页面提供了一条描述错误的短消息,但在生产中要小心使用。如果您愿意,您可以删除 layout.blade.phpminimal.blade.php,因为它们不再需要。