Reputation: 951
I'm building a REST API using controllers in Laravel 3, and I'd like to achieve the following structure:
/api/controller/{param}/method/{optional param}
Currently, I have individual routes set up for each method, which seems like a tedious solution:
Route::any('api/ControllerA/(:any)/MethodA/(:any?)','api.ControllerA@MethodA');
Route::any('api/ControllerA/(:any)/MethodB/(:any?)','api.ControllerA@MethodB');
// etc.
Route::any('api/ControllerB/(:any)/MethodA/(:any?)','api.ControllerB@MethodA');
// etc.
and at the end, a catch-all to handle invalid calls:
Route::any('api/(:all)',function(){
// return invalid call 404 response
});
This works just fine, but I can't imagine this being the optimal solution. I might consider doing something like this post suggests, but I feel like that would lead to some bulky API controllers. Is there something I'm missing?
Upvotes: 0
Views: 393
Reputation: 5773
Currently Laravel 3 doesn't support urls like controller/{param}/method/{param}
without defining them manually. Laravel 4 supports that but only for default resourceful routes (index, show, update, delete, etc). You cannot define custom actions tho.
I would suggest you to stick with your approach for now. It's what we've being doing on Laravel 3. If you really dislike that, you could extend \Laravel\Routing\Router
with your own implementation.
Upvotes: 1