Question

I have the following code inside my app/start/global.php file:

App::missing(function($exception){
    return Response::view('missing', array('url' => Request::url()), 404);
});

And I have a file called missing.blade.php at app/view. However, the above code gives me a FatalErrorException, telling me "Call to a member function getPath() on a non-object". The formatting of the otherwise pretty error page that I got the above information from is also messed up.

But everything works fine when I change my code in global.php to the following:

App::missing(function($exception){
    return Response::make("Page not found", 404);
});

I don't get what's going on. How can I display a specific view when a route is not found?

EDIT: Here is my missing.blade.php file:

@extends('master')

@section('header')
    <h2>404 Error</h2>
@stop

@section('content')
    <p>
        Unable to locate page.
    </p>
@stop

EDIT 2: Also inside my app/views folder, I have a master.blade.php file with the following structure:

...
@yield('header')
...
@yield('content')
...
Was it helpful?

Solution

The following should work for you and gives you more control on other errors as well:

App::error(function(Exception $exception, $code)
{
    Log::error($exception);
    switch ($code)
    {
        case 403:
            return 'Your 403 message';//or load any custom view
             break;
        case 404:
             return Redirect::to('/');//or load any custom view
              break;
        case 500:
             return 'Your 500 Error Message';//or load any custom view
              break;
        default:
            return Redirect::to('/');//or load any custom view
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top