laravel应用通配符路由和控制器

时间:2017-03-14 03:58:21

标签: php laravel

我有一些看似重复的路线。

function generateRoute($name) {
      Route::get("admincp/$name", "{$name}Controller@index");
      Route::post("admincp/$name/store", "{$name}Controller@store");
      Route::get("admincp/$name/{id}/edit", "{$name}Controller@edit");
      Route::patch("admincp/$name/{id}/update", "{$name}Controller@update");
      Route::get("admincp/$name/{id}/destroy", "{$name}Controller@destroy");
}

我不想重复自己。我可以在laravel中做这样的事吗?

ave

1 个答案:

答案 0 :(得分:1)

使用资源路线:

   Route::group(['prefix' => 'admincp'], function () {
        Route::resource('point', 'PointController');
        Route::resource('faq', 'FaqController');
        Route::resource('slider', 'SliderController');
    }