Laravel 4 Exception: NotFoundHttpException Laravel 4 Exception: NotFoundHttpException symfony symfony

Laravel 4 Exception: NotFoundHttpException


A NotFoundHttpException is basically just a 404 in your application. Unfortunately the exception message doesn't even tell you the URL of the request that triggered the exception, which makes it difficult to understand these errors when you see them in your logs.

To give you more debugging information, set up your own 404 handler. Here's a simple handler which will log the URL (so you know what was requested to trigger the error) and the user agent (to help you figure out who or what made the request) and return a view and 404 code:

App::missing(function($e) {    $url = Request::fullUrl();    $userAgent = Request::header('user-agent');    Log::warning("404 for URL: $url requested by user agent: $userAgent");    return Response::view('errors.not-found', array(), 404);});

Put it in app/start/global.php.


I got this problem because I had capitalized the name of a parent directory and didn't capitalize it in the URL. That's why I got the error.

I was using this url localhost/laravel/todo2/public/fooand in fact it worked if all I typed was:localhost/Laravel/todo2/public/but if I typed anything after the public/ it would give that error.

if I used this with Laravel capitalized localhost/Laravel/todo2/public/foo

the routes after public/ would work


It's really hard to say for sure what is causing this without knowing your code. Looking at the stack trace of the error, it's clear that the Router is dispatching it and I guess it has nothing to do with the background job itself, but rather the API's it calls.

In your specific case, the exception is throw after a ResourceNotFoundException, which happens when there's no route defined for such URL pattern.

Possible problems:

If the background job does a file_get_contents or curl on your own API's, it may be calling a route that does not exist and then throwing that exception.

If you don't have control of the URL's the background job is downloading, it may be trying to fetch an URL like 127.0.0.1, localhost or anything like that.