Handling 404 Errors NotFoundHttpException

First off, I want to thank to my grandfather, granma, mother, father, sister, brother, and whoever read this, especially Google who gave me only partial answer to my problem. So, here I create one of my complete solution to handle the 404 Errors on Laravel.

Why my Laravel keeps showing the NotFoundHttpException error? Usually it appears like Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException.

Why NotFoundHttpException

It is because Application Debug Mode in your Laravel/app/config/app.php is set true. You can change it from ‘debug’ => true to ‘debug’ => false.

Creating Handle for 404 Error

First you have to set the Application Debug Mode to false, if it’s already done you can continue. Open your Laravel/app/start/global.php and then find the Application Error Handler section. You must find something like this.

App::error(function(Exception $exception, $code)
{
	Log::error($exception);
});

I know you are lazy. Change the script by copy-pasting the script below. And don’t forget to save.

App::error(function(Exception $exception, $code)
{
	Log::error($exception);
	
	if (Config::get('app.debug')) {
    	return;
    }

    switch ($code)a
    {

        case 404:
        	return Response::view('errors.missing', array(), 404);
        default:
        	return Response::view('errors.missing', array(), $code);
    }
});

Creating Custom Page for 404 Error

Now you create new folder named ‘errors’ in Laravel/app/views/ anad create missing.blade.php. So, the full filepath will look like this Laravel/app/views/errors/missing.blade.php.

You can fill the missing.blade.php with words, statements, and whatever you like. But please do not harass me. If you want to see complete documentation about handling error 404 in Laravel you can visit this Laravel Error Handling documentation, it’s very very very very complete. You must be come back here again after read that bullshit docs. Cheers