@mike What services like Heroku do is allow you to create a CNAME that maps to the sub-domain version of your application’s URL.
I think in this scenario, you’ll need to do some routing logic to map a custom domain name a customer’s added to their actual subdomain, and then group your routes using the sub-domain:
// Marketing site routes
Route::group(['domain' => 'example.com'], function () {
// Marketing home page
Route::get('/', 'HomeController');
});
// Customer routes
Route::group([
'domain' => '{account}.example.com',
'middleware' => ['any', 'middleware', 'here'],
'namespace' => 'Account',
], function () {
// Customer home page route
// All routes in this group will receive $account as first parameter
// Use route–model binding to have $account be an Account instance
Route::get('/', 'HomeController');
});
Whatever approach you take, make sure to cache you’re domain-to-sub-domain look-ups. You don’t want to be performing the same database query on each and every HTTP request. Cache the mappings, and then re-cache them when a domain is added/removed.