Reputation: 189
I'm using Laravel for a Cat Management App and I'm having trouble creating Cats as Laravel returns a 404 for my routes.
Route::get('cats/create', function() {
$cat = new Cat;
return View::make('cats.edit')
->with('cat',$cat)
->with('method','post');
});
This route returns a stack trace which throws a not found HTTP exception.
Why Isn't this working? The address I'm typing is
localhost:8000/cats/create
This is the result of PHP artisan routes.
Upvotes: 0
Views: 1993
Reputation: 15760
You have the following routes in your application:
GET|HEAD cats/{cat}
GET|HEAD cats/create
If you hit http://localhost/cats/create
that's going to get matched by the first route. It looks like you're using Route Model Binding so your application is trying to interpret "create" as the ID for an instance of the cats
model - that's where it's failing.
Upvotes: 1
Reputation: 2609
You have to rearrange your route definitions, so that the route for cats/create is defined before the route for cats/{cat}.
Upvotes: 1
Reputation: 644
i believe the route needs to start with a front slash
change:
Route::get('cats/create', function() {
to:
Route::get('/cats/create', function() {
final output:
Route::get('/cats/create', function() {
$cat = new Cat;
return View::make('cats.edit')
->with('cat',$cat)
->with('method','post');
});
Upvotes: 0