Laravel 4.2组中非模糊的命名路由

时间:2014-09-13 11:21:05

标签: laravel-4 laravel-routing

我在routes.php中有以下代码:

    Route::group(['prefix' => 'dev/order'], function() {
            Route::get('create', ['as' => 'dev.order.create', 'uses' => 'OrderController@create']);
            Route::get('create-pack', ['as' => 'dev.order.create-pack', 'uses' => 'OrderController@createPack']);
        }
    );

如何摆脱重复的动作名称,' dev.order'和' OrderController'参数中的子串?当通过

查看时,Route :: controller()和Route :: resource()创建未命名的路由
php artisan routes

虽然我需要一组命名路由到一个具有公共前缀的控制器。

1 个答案:

答案 0 :(得分:0)

不幸的是,在Laravel中还没有路由名称前缀,因此,为了删除重复的字符串,你可以这样做:

$prefix = 'dev.order.';
$controller = 'OrderController@';

Route::group(['prefix' => 'dev/order'], function() use ($prefix, $prefix)
{
    Route::get('create', ['as' => $prefix.'create', 'uses' => $controller.'create']);
    Route::get('create-pack', ['as' => $prefix.'create-pack', 'uses' => $controller.'createPack']);
});