How to customize the Laravel 4 error page?

1

When an error occurs in Laravel 4 , with the setting of app.debug equal to false , the following page is returned:

In this case, for both% and% errors, this page is displayed.

Is there any way to change the page that is displayed when only the 400 error occurs?

Is there a way to set a specific 500 for each type of error with given http response code?

Example, I want to set an error page for 404 status and another for view . How do I do this?

    
asked by anonymous 24.02.2016 / 15:07

1 answer

1

I searched for the "resources" but did not find it, however this link link you can do this:

App::error(function($exception, $code)
{
    $error = array( 'error' => $exception->getMessage());
    switch ($code)
    {
        case 403:
            return Response::view('errors.403', $error, 403);

        case 404:
            return Response::view('errors.404', $error, 404);

        case 500:
            return Response::view('errors.500', $error, 500);

        default:
            return Response::view('errors.default', $error, $code);
    }
});

Any request where the response is related to an error of http , Laravel uses this App::error method to verify that you have made some customization for a given error. The way this is done is to check if there is anything being returned by the past closure as the App::error argument. If you return null or none (return empty), Laravel will use the default error (which is whoops!).

Remembering that when you set up the error page, the App::abort() call is also affected. That is, if you do this ...

return App::abort('Acesso não autorizado', 403);

... It will no longer be called the whoops! error, but rather what you have defined. In this case, the value of the arguments $code and $exception->getMessage() will be the values passed to App::abort() ;

    
24.02.2016 / 15:21