laravel - 仅为生产设计 500 错误页面

标签 laravel laravel-5.4

我正在寻找一种现代(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. The HttpException instance raised by the abort function will be passed to the view as an $exception variable.

https://laravel.com/docs/5.4/errors#custom-http-error-pages

关于laravel - 仅为生产设计 500 错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42486562/

相关文章:

php - Laravel - 找不到关系时用空数组替换 null

php - 如何在 laravel 调度程序中访问 Controller 中的方法?

Mysql json列输出反斜杠

laravel - Gulp 文件不复制字体

php - Laravel 检查给定 url 的路由是否存在于路由中

php - 如何订购数据两次。但是使第一个订单无效

laravel - Javascript - 使用 moment.js 格式化日期/时间

php - Laravel 搜索属于

javascript - Laravel-9 jQuery Timepicker 禁用特定时间如何?

laravel - Laravel 中的 weekOn() 链接