5

I am trying to create a sub-domain in laravel. The subdomain will be something like merchant.example.com and they will be more links such as merchant.example.com/login merchant.example.com/myaccount so this is what I tired

Route::get('.partner/', array(
'as' => 'partner-home',
'uses' => 'HomeController@partnerHome'
));

but just redirect me to the main domain. Any idea how to this please.

peterh
  • 11,875
  • 18
  • 85
  • 108
Baako
  • 263
  • 2
  • 4
  • 11

1 Answers1

5

You can register a route group to have a certain domain:

Route::group(array('domain' => 'partner.myapp.com'), function(){
    Route::get('/', array(
        'as' => 'partner-home',
        'uses' => 'HomeController@partnerHome'
    ));
});
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
  • 1
    thanks but do i need to hard code "myapp.com"? can't i get the actually domain be better? – Baako Feb 02 '15 at 19:55
  • 5
    Note that there is no save way to figure out the current domain (because there are tlds with two segments like `.co.uk`. You could add a value `domain` inside `config/app.php`. And retrieve it like `Config::get('app.domain')` to make it configurable for different environments. – lukasgeiter Feb 02 '15 at 20:16