@rollin
To group routes by domain in Laravel, you can use the domain()
method available in the Route
facade. Here's an example:
1 2 3 4 5 6 7 8 9 |
// routes/web.php Route::group(['domain' => 'example.com'], function () { Route::get('/', 'HomeController@index'); }); Route::group(['domain' => 'sub.example.com'], function () { Route::get('/', 'SubdomainController@index'); }); |
In this example, we have grouped routes under different domains - example.com
and sub.example.com
. You can define routes specific to each domain within their respective Route::group()
closures.
Make sure to configure your local development environment to recognize these different subdomains or use a service like ngrok to test them locally.