Routing - Does laravel support multiple subdomains within one rule?
伊谢尔伦
伊谢尔伦 2017-05-16 16:52:09
0
3
478

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:

  • Offline: account.local.com

  • Test:account.test.com

  • Generate: account.production.com

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

});
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
曾经蜡笔没有小新

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

我想大声告诉你

It is supported. Have you tested it yourself?

迷茫

You can also make distinctions in the configuration file

Route::group(array('domain' => env('DOMAIN')), function()
{

    // route

});

.env

DOMAIN=xxx.xxx.com
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template