Laravel 5 get route prefix in controller method

2019-02-16 08:07发布

I am working in Laravel 5.0 app.

I have created route group like below,

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

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

I want to get the current route prefix in DashboardController's index method. I dont know how to do that. I could not find this in documentation. Please help me.

标签: php laravel-5
3条回答
倾城 Initia
2楼-- · 2019-02-16 08:35

You can do this two way

Type-hinting Request in method

 public function index(\Illuminate\Http\Request $request){
  dd($request->route()->getPrefix());
 }

or

 public function index(){
  dd($this->getRouter()->getCurrentRoute()->getPrefix());
 }

I hope this helps.

查看更多
乱世女痞
3楼-- · 2019-02-16 08:39

Try this

$request = Request();
$request->route()->group;
查看更多
走好不送
4楼-- · 2019-02-16 08:47
Request()->route()->getPrefix()
查看更多
登录 后发表回答