Reputation: 111
I've got the following snippet successfully routing subdomain request. I'm looking for a way where I can detect the subdomain and do some quick logic to assign a value to a global variable depending on the subdomain. Where could I do this?
Route::group(array('domain' => '{username}.murch.co'), function() {
Route::controller('checkout', 'CheckoutController');
Route::get('/', 'UserController@getProfile');
});
I'd like to do something like
Route::group(array('domain' => '{username}.murch.co'), function() {
$var = "dog".$username;
View::share('var', $var);
Route::controller('checkout', 'CheckoutController');
Route::get('/', 'UserController@getProfile');
});
Upvotes: 0
Views: 3189
Reputation: 110
For Laravel 5.x, you can call it from anywhere - controller, view, etc.
Route::current()->parameter('username');
Upvotes: 0
Reputation: 111
I still don't know how to achieve this is routes.php but I ended up finding a solution using filters
App::before(function($request)
{
$urlParts = explode('.', $_SERVER['HTTP_HOST']);
$subdomain = $urlParts[0];
$userModel = new User;
$user = $userModel->getUserByUsername($subdomain);
View::share('user', $user);
});
Upvotes: 1