Do I understand right: if I want to display custom pages for 403, 404 etc. errors I should check whether app.debug is set to false:
if (!Config::get('app.debug')) {
App::error(function(Exception $exception, $code)
{
switch ($code) {
case 403:
return Response::view('errors.403', array(), 403);
case 404:
return Response::view('errors.404', array(), 404);
case 500:
return Response::view('errors.500', array(), 500);
default:
return Response::view('errors.default', array(), $code);
}
Log::error($exception);
});
}
Because, if I set App::error handler without checking app.debug I'll always get these custom pages instead of detailed info
Am I right?
By default, error detail is enabled for your application. This means that when an error occurs you will be shown an error page with a detailed stack trace and error message. You may turn off error details by setting the debug option in your app/config/app. php file to false .
Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.
Create Custom 404 Error Page You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.
You could just move the if statement into the app::error function. So that the error is always logged, and the custom error page is only shown when app.debug is false.
App::error(function(Exception $exception, $code)
{
Log::error($exception);
if (!Config::get('app.debug')) {
return Response::view('errors.index', $code);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With