我正在寻找一种现代(Laravel 5.4)方式来仅针对 HTTP(非 ajax/fetch)响应显示自定义 500 错误页面。我读了一些帖子,但每个回复看起来都像是一个把戏或者已经过时了。 \App\Exceptions\Handler
中可能有一些东西需要修改,但我没有找到“正确的方法”。
是否有一种简单的方法可以在 Laravel 5.4 中显示 fatal error (未捕获,返回 500)的特定页面?
换句话说,当我的一个 Controller 出现语法错误时,它会显示“哎呀出了问题”以及一些 HTML 和 500 错误代码。我想显示其他内容,其规则与默认行为相同(理想情况下仅适用于 HTML 浏览器,不适用于 ajax/fetch 等)。
编辑:仅在生产环境中。
最佳答案
Laravel makes it easy to display custom error pages for various HTTP status codes. For example, if you wish to customize the error page for 404 HTTP status codes, create a
resources/views/errors/404.blade.php
. This file will be served on all 404 errors generated by your application. The views within this directory should be named to match the HTTP status code they correspond to. TheHttpException
instance raised by the abort function will be passed to the view as an $exception variable.
关于laravel - 仅为生产设计 500 错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42486562/