I'm trying to have an admin subdomain (like this)
Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return view('welcome');
});
});
but admin.localhost acts just like localhost. How I'm supposed to do this correctly?
I'm using Laravel 5.1 and MAMP on OSX
Laravel processes routes on a first-come-first-serve basis and therefore you need to place your least specific routes last in the routes file. This means that you need to place your route group above any other routes that have the same path.
For example, this will work as expected:
Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return "This will respond to requests for 'admin.localhost/'";
});
});
Route::get('/', function () {
return "This will respond to all other '/' requests.";
});
But this example will not:
Route::get('/', function () {
return "This will respond to all '/' requests before the route group gets processed.";
});
Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return "This will never be called";
});
});