禁用 Laravel 的内置错误屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25665061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
disable laravel's built in error screen
提问by Amin
I want to disable Laravel's error screen that shows the errors/exceptions with debugging information and functions trace. Mostly because I'm using Laravel as mobile API backend and those responses are harder to read on a mobile device.
我想禁用 Laravel 的错误屏幕,该屏幕显示带有调试信息和函数跟踪的错误/异常。主要是因为我使用 Laravel 作为移动 API 后端,而这些响应在移动设备上更难阅读。
Please notice that I want the errors, but not the fancy error page.
请注意,我想要错误,而不是花哨的错误页面。
Any suggestions?
有什么建议?
回答by Alley Shairu
Go to Laravel project -> app folder-> config folder -> app.php set
转到 Laravel 项目 -> 应用文件夹 -> 配置文件夹 -> app.php 设置
'debug' => false,
This will show a simple error page like Ops! Something went wrong.
这将显示一个简单的错误页面,如 Ops!出了些问题。
Edit:
编辑:
Laravel App facade provides a way to way catch the exceptions using error method as mentioned in the Laravel docs
Laravel App 外观提供了一种使用Laravel 文档中提到的错误方法捕获异常的方法
App::error(function(Exception $exception)
{
// handle your exception
});
You can place App::error method in the filters.php
您可以将 App::error 方法放在 filters.php 中
and Laravel is using Symfony to display those pages if you want to further go down. I have not really tried to change this thing, maybe someone will come up with a better answer.
如果你想继续往下看,Laravel 正在使用 Symfony 来显示这些页面。我还没有真正尝试过改变这件事,也许有人会想出更好的答案。