Laravel将子域作为值传递给另一条路线

时间:2019-05-27 15:11:55

标签: laravel

现在我有此代码

    Route::group(['domain' => '{subdomain}.'.env('DOMAIN')], function()
{
    Route::any('/', function($subdomain)
    {
        Route::get('{/subdomain}/{identifier}/{reCreate?}','AController@index');
    });
});

我想将{subdomain}传递给Route::get('{/subdomain}/{identifier}/{reCreate?}','AController@index');,以便在调用subdomain.localhost/identifier时调用AController@index,我应该将subdomain的值传递给AController@index

3 个答案:

答案 0 :(得分:1)

我认为通过使用Route::input('subdomain');,您可以访问subdomain参数。

内部AController:

public function index() {
   dd(Route::input('subdomain'));
}

答案 1 :(得分:1)

请尝试这个。

Route::domain('{account}.myapp.com')->group(function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});

答案 2 :(得分:0)

我想出了答案,谢谢大家的帮助, 答案就是调用route::group

内的路由
Route::group(['domain' => '{subdomain}.'.env('DOMAIN')], function()
{
    Route::any('/{identifier}/{reCreate?}','AController@index');
});

在Controller函数index中,我可以像常规function($subdomain)一样访问该值