Question

Just got "Getting Started with Laravel 4" ebook from Raphael Saunier and tried the tutorial, while writing the Route::get in routes.php i got an error saying that

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

When I wrote the code like this

Route::get('cats/{cat}', function($cat){
    return View::make('cats.single')->with('cat', $cat);
});

Route::get('cats/create', function() {
$cat = new Cat;
return View::make('cats.edit')
->with('cat', $cat)
->with('method', 'post');
});

but after downloading the source file from packtpub, i cross check all the code are exactly the same, but only the sequence are different, like this

Route::get('cats/create', function() {
$cat = new Cat;
return View::make('cats.edit')
->with('cat', $cat)
->with('method', 'post');
});

Route::get('cats/{cat}', function($cat){
    return View::make('cats.single')->with('cat', $cat);
});

does route sequence differences like this matter on routes.php? how can i now the error is from the route sequence?

Was it helpful?

Solution

Yes. The sequence definitely matters. Once a route matches your current url, the rest of the routes aren't checked anymore.

Since Route::get('cats/{cat}', ...) matches against cats/ + anything, it also includes cats/create.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top