Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom 500 error page only for production in Laravel

I want to have a custom 500 error page. This can be done simply by creating a view in errors/500.blade.php.

This is fine for production mode, but I no longer get the default exception/ debug pages when in debug mode (the one that looks grey and says "Whoops something went wrong").

Therefore, my question is: how can I have a custom 500 error page for production, but the original 500 error page when debug mode is true?

like image 776
Yahya Uddin Avatar asked Mar 06 '17 12:03

Yahya Uddin


Video Answer


1 Answers

Simply add this code in \App\Exceptinons\Handler.php:

public function render($request, Exception $exception)
{
    // Render well-known exceptions here

    // Otherwise display internal error message
    if(!env('APP_DEBUG', false)){
        return view('errors.500');
    } else {
        return parent::render($request, $exception);
    }
}

Or

public function render($request, Exception $exception)
{

    // Render well-known exceptions here

    // Otherwise display internal error message
    if(app()->environment() === 'production') {
        return view('errors.500');
    } else {
        return parent::render($request, $exception);
    }
}
like image 98
Desh901 Avatar answered Dec 06 '22 00:12

Desh901