Laravel优化路线

时间:2016-03-13 18:40:59

标签: php laravel optimization routes laravel-5.2

有没有机会减少routes.php

我有一种用于日,周,月和年操作的模型方法。这是仅用于每周操作的路线,但我对其他时段具有相同的路线。有没有机会减少它们?

Route::get('capacity/{capacity}/createweekly', [
    'as' => 'admin.capacity.createweekly', 'uses' => 'CapacityController@createweekly'
]);
Route::put('capacity/{capacity}/storeweekly', [
    'as' => 'admin.capacity.storeweekly', 'uses' => 'CapacityController@storeweekly'
]);
Route::get('capacity/{period}/activateweekly', [
    'as' => 'admin.capacity.activateweekly', 'uses' => 'CapacityController@activateweekly'
]);
Route::get('capacity/{period}/deactivateweekly', [
    'as' => 'admin.capacity.deactivateweekly', 'uses' => 'CapacityController@deactivateweekly'
]);
Route::get('capacity/{period}/deleteweekly', [
    'as' => 'admin.capacity.deleteweekly', 'uses' => 'CapacityController@deleteweekly'
]);
Route::get('capacity/{period}/editweekly', [
    'as' => 'admin.capacity.editweekly', 'uses' => 'CapacityController@editweekly'
]);
Route::post('capacity/{period}/updateweekly', [
    'as' => 'admin.capacity.updateweekly', 'uses' => 'CapacityController@updateweekly'
]);

1 个答案:

答案 0 :(得分:0)

您可以尝试将它们分组:

Route::group(['as' => 'admin.capacity.', 'prefix' => 'capacity'], function () {
        Route::get('{capacity}/createweekly', [
                'as' => 'createweekly', 'uses' => 'CapacityController@createweekly'
            ]);
        Route::put('{capacity}/storeweekly', [
                'as' => 'storeweekly', 'uses' => 'CapacityController@storeweekly'
            ]);
        Route::get('{period}/activateweekly', [
                'as' => 'activateweekly', 'uses' => 'CapacityController@activateweekly'
            ]);
        Route::get('{period}/deactivateweekly', [
                'as' => 'deactivateweekly', 'uses' => 'CapacityController@deactivateweekly'
            ]);
        Route::get('{period}/deleteweekly', [
                'as' => 'deleteweekly', 'uses' => 'CapacityController@deleteweekly'
            ]);
        Route::get('{period}/editweekly', [
                'as' => 'editweekly', 'uses' => 'CapacityController@editweekly'
            ]);
        Route::post('{period}/updateweekly', [
                'as' => 'updateweekly', 'uses' => 'CapacityController@updateweekly'
            ]);
    });