disable laravel's built in error screen [dupli

2019-02-26 17:02发布

问题:

This question already has an answer here:

  • Disable laravel error handler 6 answers

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.

Any suggestions?

回答1:

Go to Laravel project -> app folder-> config folder -> app.php set

'debug' => false,

This will show a simple error page like Ops! Something went wrong.

Edit:

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
});

You can place App::error method in the 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.