問題描述
我想禁用 Laravel 的錯誤屏幕,該屏幕顯示帶有調試信息和函數跟蹤的錯誤/異常.主要是因為我使用 Laravel 作為移動 API 后端,而這些響應在移動設備上更難閱讀.
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.
請注意,我想要錯誤,而不是花哨的錯誤頁面.
Please notice that I want the errors, but not the fancy error page.
有什么建議嗎?
推薦答案
進入Laravel項目->app文件夾->config文件夾->app.php設置
Go to Laravel project -> app folder-> config folder -> app.php set
'debug' => false,
這將顯示一個簡單的錯誤頁面,如 Ops!出了點問題.
This will show a simple error page like Ops! Something went wrong.
Laravel App Facade 提供了一種使用 Laravel 文檔中提到的錯誤方法來捕獲異常的方法
Laravel App facade provides a way to way catch the exceptions using error method as mentioned in the Laravel docs
App::error(function(Exception $exception)
{
// handle your exception
});
你可以在filters.php中放置App::error方法
You can place App::error method in the filters.php
如果你想進一步往下看,Laravel 正在使用 Symfony 來顯示這些頁面.我還沒有真正嘗試過改變這件事,也許有人會想出更好的答案.
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 的內置錯誤屏幕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!