Laravel 5在控制器方法中获取路由前缀

19 php laravel-5

我在Laravel 5.0应用程序中工作.

我创建了如下路线组,

 Route::group(['prefix' => 'expert'], function () {

    Route::get('dashboard', [
          'as'   => 'expert.dashboard',
          'uses' => 'DashboardController@index'
    ]);
 ]);
Run Code Online (Sandbox Code Playgroud)

我想在目前的路由前缀DashboardControllerindex方法.我不知道该怎么做.我在文档中找不到这个.请帮我.

pin*_*sia 35

你可以这两种方式做到这一点

Request方法中的类型提示

 public function index(\Illuminate\Http\Request $request){
  dd($request->route()->getPrefix());
 }
Run Code Online (Sandbox Code Playgroud)

要么

 public function index(){
  dd($this->getRouter()->getCurrentRoute()->getPrefix());
 }
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.