Laravel: How to create a route for multiple domains

Viewed 183

In Laravel it is possible to target specific domains in routes like so:

Route::domain('example1.com')->group(...);

But how can I create a route that targets multiple domains like so:

Route::domain(['example1.com', 'example2.com'])->group(...);
1 Answers

You can use Pattern for this

Route::pattern('subdomain', '(dev.app|app)');
Route::group(['domain' => '{subdomain}.example.com'], function () {
  ...
});

--

Route::pattern('subdomain', '(dev.app|app)');
Route::pattern('domain', '(example.com|example.dev)');
Route::group(['domain' => '{subdomain}.{domain}'], function () {
  ...
});
Related