I propose a change to the Route@group
method so that you can supply an array of domains. Currently you have to duplicate the calls:
Route::group(['domain' => 'foo.bar.dev'], function($route) {
// Do stuff
});
Route::group(['domain' => 'foo.bar'], function($route) {
// Do the exact same stuff
});
Whereas you'd be able to do:
Route::group(['domain' => ['foo.bar.dev', 'foo.bar']], function($route) {
// Do stuff
});
I've had to do this for developing locally, where our VHOSTs are setup with the .dev
extension. The code does the exact same thing though.
You don't have to repeat code.
$callback = function() {};
Route::group(['domain' => 'whatever'], $callback);
Route::group(['domain' => 'whatever-2'], $callback);
I also had to do this, I would like to see the 'domain'
allow an array. :+1:
Also want domain allow array
+1
+1
+1
+1
+1
+1
Can we please have this, there seems like there is no other way to do it. This would simplify everything!
I provided a way to do it up above.
Yeah, got it working like that but do you ever plan on allowing arrays for domains? I'm sure many people would find it easier to just enter an array. Thoughts?
+1
Could you please reconsider it @taylorotwell ?
A lot of people seem to want this feature.
Route::macro("domain", function(array $domains, \Closure $definition) {
foreach ($domains as $domain) {
Route::group(['domain' => $domain], $definition);
}
});
Route::domain(['foo.bar.dev', 'foo.bar'], function($route) {
// Do stuff
});
@taylorotwell but what if like google i want google.com.ng, google.com, google.co.uk and possibly 50 more. wont it make sense to just put those domains in an array and link it to the route instead of repeating the code 50 times ...
Love the macro solution from @crynobone. Thanks
I forget that so many features utilize macroable.
@Dsaint109 the resolved route is repeated internally, so it still basically 50 repeated routes even if this is added to the core.
Would be awesome to pass an array of domains!
Most helpful comment