search

Home  >  Q&A  >  body text

Routing - Does laravel support multiple subdomains within one rule?

We all know that laravel’s routing supports subdomain names. as follows

Route::group(array('domain' => '{account}.local.com'), function()
{

    Route::get('user/{id}', function($account, $id)
    {
        //
    });

});

But I now encounter a problem. The local development environment, test environment and online production environment are different subdomains.
For example:

In addition to writing the routing rules three times, I accidentally. I wonder if there is a way to support these three subdomain names in one routing rule at the same time?

Route::group(array('domain' => '{account}.local.com'), function()
{

    // route

});

Route::group(array('domain' => '{account}.test.com'), function()
{

    // route

});

Route::group(array('domain' => '{account}.production.com'), function()
{

    // route

});

-------------------------------Dividing line-------------- ----------------------------

The following is sufficient.

Route::group(array('domain' => 'account.{env}.com'), function()
{

    // route

});

Because I have other domain names and don’t want to mix common route, so I need to distinguish them

Route::group(array('domain' => 'help.{env}.com'), function()
{

    // route

});
伊谢尔伦伊谢尔伦2752 days ago480

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 16:54:09

    The routing configuration of the three environments does not need to be configureddomain. As long as your three domain names point to Laravel, they will naturally be shared

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:54:09

    It is supported. Have you tested it yourself?

    reply
    0
  • 迷茫

    迷茫2017-05-16 16:54:09

    You can also make distinctions in the configuration file

    Route::group(array('domain' => env('DOMAIN')), function()
    {
    
        // route
    
    });

    .env

    DOMAIN=xxx.xxx.com

    reply
    0
  • Cancelreply