Scenario:
Using Laravel 5.2 / Digital Ocean / Laravel Forge (enabled wildcard domains on installing the site)
Every user has its own subdomain.
Main domain: mydomain.com
User domain: {user}.mydomain.com
Added a DNS record (A) - * - ip address to the domain.
Routes:
Route::group(['domain' => '{user}.mydomain.com'], function () {
return 'This user has a domain.';
Route::get('user/{id}', function ($account, $id) {
//
});
});
Route::get('/', function () {
return view('pages.home');
});
Problem:
Every user subdomain will skip the group domain and will go into the normal Route get '/'. So it wont return 'This user has a domain.';. What is going wrong?
Laravel Docs Wildcard Subdomains
First, you need to remove return 'This user has a domain.'; as it will prevent this route user/{id} from being registered. Second, try to add a default route to your sub-domains:
Route::group(['domain' => '{user}.mydomain.com'], function () {
Route::get('/', function ($user) {
return "This user has a domain: $user";
});
Route::get('user/{id}', function ($account, $id) {
//
});
});
I hope this will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With