本文介绍了Laravel 5在控制器方法中获取路由前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel 5.0应用程序.
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'
]);
]);
我想在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.
推荐答案
您可以通过两种方式进行
You can do this two way
方法中的类型提示Request
public function index(\Illuminate\Http\Request $request){
dd($request->route()->getPrefix());
}
或
public function index(){
dd($this->getRouter()->getCurrentRoute()->getPrefix());
}
我希望这会有所帮助.
这篇关于Laravel 5在控制器方法中获取路由前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!