Can I group multiple domains in a routing group in

2019-02-01 07:35发布

Let's say I have the following:

Route::group(array('domain' => array('admin.example.com')), function()
{
    ...
});

Route::group(array('domain' => array('app.example.com')), function()
{
    ...
});

Route::group(array('domain' => array('dev.app.example.com')), function()
{
    ...
});

Is there any way to have multiple domains share a routing group? Something like:

Route::group(array('domain' => array('dev.app.example.com','app.example.com')), function()
{
    ...
});

8条回答
神经病院院长
2楼-- · 2019-02-01 08:04

see this link. http://laravel.com/docs/routing#sub-domain-routing

Route::group(array('domain' => '{subdomain}.example.com'), function()
{
    ...
});

or Use this package.

https://github.com/jasonlewis/enhanced-router

It help you can set where on group routing like this.

Route::group(array('domain' => '{maindomain}'), function()
{
    ...
})->where('maindomain', '.+\.example\.com$');
查看更多
一夜七次
3楼-- · 2019-02-01 08:05

Interested in this also! I'm trying to register a local development + production subdomain route, for the one controller action.

i.e.

# Local Dev
Route::group(array('domain' => "{subdomain}.app.dev"), function() {
    Route::get('/{id}', 'SomeController@getShow');
});

# Production Server
Route::group(array('domain' => "{subdomain}.app.com"), function() {
    Route::get('/{id}', 'SomeController@getShow');
});

I tried:

# Failed
Route::group(array('domain' => "{account}.app.{top_level_domain}"), function() {
    Route::get('/{id}', 'SomeController@getShow');
});

But it failed.

Not a huge issue, as DesignerGuy mentioned I can just pass in a function to both routes - but it would just be more elegant if they could be grouped :)

查看更多
狗以群分
4楼-- · 2019-02-01 08:08

Currently you cannot. I had the same 'problem'; my fix is to cycle through your subdomains with a foreach and register the routes.

查看更多
三岁会撩人
5楼-- · 2019-02-01 08:13

check in laravel docs, if you main domain is myapp, in production is myapp.com and in local environment is myapp.dev try using a *

Route::group(array('domain' => '{subdomain}.myapp.*'), 
function()
{
    ...
});
查看更多
该账号已被封号
6楼-- · 2019-02-01 08:17

according to laravel document in laravel 5.4+ you can use this way:

Route::domain('{account}.myapp.com')->group(function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});
查看更多
迷人小祖宗
7楼-- · 2019-02-01 08:20

Laravel 5.1

 

Route::pattern('subdomain', '(dev.app|app)');
Route::group(['domain' => '{subdomain}.example.com'], function () {
  ...
});

 

Route::pattern('subdomain', '(dev.app|app)');
Route::pattern('domain', '(example.com|example.dev)');
Route::group(['domain' => '{subdomain}.{domain}'], function () {
  ...
});

查看更多
登录 后发表回答