arielmejiadev / inertiajs-error-page
它为Vue组件添加了加载错误页面,并使用了在Laravel 5.7和TailwindCSS中使用的精美插图。
1.0.0
2020-11-30 08:58 UTC
Requires
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.3
This package is auto-updated.
Last update: 2024-08-29 05:37:15 UTC
README
它通过使用TailwindCSS添加了一个vue组件来加载带有Laravel 5.7精美插图的错误页面。
安装
您可以通过composer安装此包
composer require arielmejiadev/inertiajs-error-page
发布文件
php artisan vendor:publish --tag=inertiajs-errors
用法
前往 "app/Exceptions/Handler.php" 并重写render方法,然后添加另一个自定义方法
public function render($request, Throwable $exception) { $response = parent::render($request, $exception); if ($this->thereAreErrorsInProduction($response)) { return \Inertia\Inertia::render('Errors/Error', [ 'status' => $response->status(), 'message' => $exception->getMessage(), 'home' => config('app.url'), ])->toResponse($request)->setStatusCode($response->status()); } else if ($response->status() === 419) { return back()->with([ 'message' => 'The page expired, please try again.', ]); } return $response; } public function thereAreErrorsInProduction($response) { return \Illuminate\Support\Facades\App::environment('production') && in_array($response->status(), [500, 503, 404, 403, 401, 429]); }
本地测试错误页面
在您的env文件中更改
APP_ENV=production
- 记住
如果您正在使用Inertia Stack,则需要编译您的资源
npm run watch
您可以测试不同的代码响应,最简单的方法是搜索项目中不存在的路由 :) 以获取404。
贡献
有关详细信息,请参阅CONTRIBUTING
安全
如果您发现任何与安全相关的问题,请通过电子邮件arielmejiadev@gmail.com联系,而不是使用问题跟踪器。
鸣谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。