0
votes

I want to create a custom error page for 4xx http status codes (eg. 404, 400, ...). But I need the whole $app context, since I want to display my header, footer and a search field.

I have read a lot about the custom solutions in the app/start/global.php file, but this does not help. Its good for the 5xx status codes, since I do not need the $app context there (in most cases I couldn't be accessed anyways, if there was a 500).

This is fine for the 5xx:

App::error(function(Exception $exception, $code)
{
    if (App::isDownForMaintenance()) {
        return Response::make("Maintenance, brb.", 503);
    }

    if (Config::get('app.debug')) return;

    switch ($code)
    {  
        case 500: /* internal error */
        default:
            return View::make('_layouts.error_500');
    }
});

But how can I create a 4xx custom page with $app in Laravel?

My Laravel Version is: 4.2.x

1

1 Answers

0
votes

You can use App::missing() for that:

App::missing(function($exception)
{
    $app = app();
    return Response::view('errors.missing', compact('app'), 404);
});

More info: http://laravel.com/docs/4.2/errors#handling-404-errors