2014-11-24 21 views
0

試圖篩選基於通配符子域的路由。所以基本上我們有一個網站example.com。我想基於像local.admin.example.comadmin.example.com部分子域名進行過濾。Laravel如何過濾widlcard子域?

我有一個路線的設置,像這樣:

Route::group(['domain' => '{sub}.example.com', 'namespace' => 'Controllers\Admin'], function() 
{ 
    Route::get('/', function(){ return Redirect::to('/dashboard'); }); 

    Route::any('{all}', function($uri){ return Redirect::to('/404'); })->where('all', '.*'); 

})->where('sub', 'local.admin'); 

當我添加了->where它只是給我一個錯誤:

Call to a member function where() on a non-object 

基本上我只是想捕捉到域與admin什麼,讓它去那個路線組。我知道我可以用一些if陳述來做到這一點,但在我看來,對於一個團體來說,乾淨利落。或者是if陳述去這裏的路?

回答

0

請立即撥打組內的路徑要素的where功能。如果你只想得到一個特定的子域,你不需要添加一個變量,你可以將它添加到組函數中。

Route::group(['domain' => '{sub}.example.com', 'namespace' => 'Controllers\Admin'], function() 
{ 
    Route::get('/', function(){ return Redirect::to('/dashboard'); })->where('sub', 'local.admin'); 
    Route::any('{all}', function($uri){ return Redirect::to('/404'); })->where('all', '.*')->where('sub', 'local.admin'); 
}); 

OR

Route::group(['domain' => 'local.admin.example.com', 'namespace' => 'Controllers\Admin'], function() 
{ 
    Route::get('/', function(){ return Redirect::to('/dashboard'); }); 
    Route::any('{all}', function($uri){ return Redirect::to('/404'); })->where('all', '.*'); 
}); 
+0

但後來我不得不添加' - >在哪裏( '子', 'local.admin')'該組中的每個路線,似乎有點乏味。 – Rob 2014-12-30 04:49:32

+0

在這種情況下,使用我的第二個例子:) – Jerodev 2014-12-30 08:20:44