Reputation: 26467
I have for example a route group which looks like the below, for the sake of argument
Route::group(['prefix' => '1.0', function()
{
Route::any('a', 'a@a');
Route::any('b', 'a@a');
Route::any('c', 'a@a');
});
If I want to bump my version number up for example to 1.1, is there a way I can maintain routes a, b, and c without having to duplicate the group and change the prefix.
So in this case, make 1.0/a
work as well as 1.1/a
without replicating the route definition?
A use case may be such that method d@d
exists in 1.1, but not 1.0 but the 1.0 routes must remain active so that calls to the needn't switch version depending on the call they're making.
Upvotes: 1
Views: 1437
Reputation: 11057
Try the following within your routes.php
file;
$versions = array('1.0','1.1');
foreach ($versions as $version){
Route::group(['prefix' => $version, function()
{
include('path/to/version_routes.php');
});
}
I normally partial up my routes into include files. Where you place the partial containing your version routes is up to you.
Also to save redeclaring routes within your version routes partials just include to other version routes files in higher versions i.e. include 1.0 route partial in 1.1. Then you do not repeat yourself.
This will allow you to keep each of the routes within their own place for each of the versions. And also easier to add another version by just changing the array.
PLEASE NOTE: This is not tested.
Upvotes: 2