I'm scaffolding an API interface and want to be able to have multiple versions accesible via different route groups:
Route::group(array('prefix' => 'api/v1'), function()
{
// lots of routes
});
Route::group(array('prefix' => 'api/v2'), function()
{
// same as above plus some breaking changes.
});
To make it more easy to always use the latest version of the API I want to built a '/api/latest' route without copying the complete set of routes.
Is there a way to achieve this in Laravel's routing?
I'm not sure, but you could set an app config variable, where you map 'current' to a particular version number, and then do a simple string replace in the URI to swap 'current' out with the version set in the config.
the only real question is do you want to do this with Laravel or do you want to alter the $request before laravel boots.
Hmm I hoped there would be something like when you apply multipl filters to a route: using the pipe-character to combine both.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community