Laravel 5 get route prefix in controller method

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

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.

回答1:

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.



回答2:

Try this

$request = Request(); $request->route()->group; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!