Reputation: 7935
I'm trying to learn Laravel, and I created controller (using artisan's php artisan controller:make AlbumController
). Then, I added some functions there, mainly function parse
:
/**
* Parse the album.
*
* @param int $id
* @return Response
*/
public function parse($id)
{
return 'http://api.deezer.com/'.$id;
}
In routes.php
I added
Route::resource('album', 'AlbumController');
But when I try to access the parse
page (http://localhost/album/parse/123
) Laravel returns throw new NotFoundHttpException();
.
What did I do wrong?
Upvotes: 2
Views: 993
Reputation: 24077
parse
is not an included route in Laravel's resourse controller. Run php artisan routes
to see your current route structure.
If you want to use the parse
method in your controller you should define the route manually. Add something like
Route::get('album/parse/{id}', ['uses' => 'AlbumController@parse']);
to your routes file.
As an aside, the resource controller can be a handy way to get your CRUD routes up and running but it is good practice to define most of your routes explicitly as your routes.php
file is useful documentation for your application and it makes the workings of it much easier to follow.
Upvotes: 3
Reputation: 6653
You need to change the route to
Route::get('album/parse/{id}', 'AlbumController@parse');
More of routing with parameters can you find HERE inside the Laravel Docs
And the docs with some information about Routing with Controllers
An little part of my route to give you an idea of how it could look:
Route::get('/partijen/nieuw', 'PartijenController@nieuw');
Route::post('/partijen/nieuw', 'PartijenController@save_new');
Route::get('/partijen/edit/{id}', 'PartijenController@edit');
Route::post('/partijen/edit/{id}', 'PartijenController@save_edit');
Upvotes: 1