2013-07-16 23 views
0

有没有办法做出类似这样的事情?Laravel 4:命名组中的命名路线

Route::group(array('as' => 'admin', 'prefix' => 'admin', 'before' => 'admin'), function() 
{ 
    Route::get('/', array('as' => 'home', 'uses' => '[email protected]')); 
    Route::get('users', array('as' => 'users', 'uses' => '[email protected]')); 
}); 

的目标是不包括在所有名称为 “admin”,并为上面的例子像这样的链接:

URL::route('admin.home'); 
URL::route('admin.users'); 

上面的例子不工作:

Illegal offset type in unset 
laravel/bootstrap/compiled.php:5053 

在作品中使用非公布路线命名的组。 非团体工作中的命名路线也是如此。 但不在一起。

回答

7
Route::group(['prefix' => 'admin', 'before' => 'adminAuth'], function(){ 
    // If you do not want to repeat 'admin' in all route names, 
    // define the value here 
    $r = 'admin'; 

    Route::get('users', ['as' => "{$r}.users", 'uses' => '[email protected]']); 
    Route::get('/', ['as' => "{$r}.root", 'uses' => '[email protected]']); 
}); 

在YOUT的意见/重定向可以使用URL::action('[email protected])和Laravel就会知道重定向/点......

+0

但你的路由组中使用“prefix->管理” - 我不认为你需要重新附加前缀到每个单独的路线? – Laurence

+1

前缀用于捕获URL,因此您不需要在组内写入“admin/users”,URL的“用户”部分就足够了。它与路由名称无关 – Andreyco

+0

arh - ok - 有道理 – Laurence