这期内容当中小编将会给大家带来有关使用laravel怎么获取当前url的别名,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
如下所示:
Route::get('/xiongtest', [
'as' => 'xiong.test',
'uses' => 'XiongTestController@index'
]);以上路由为例
在模版中可以使用route('xiong.test')来获取该路由的真实地址。
在XiongTestController@index中,可以使用以下方法获取路由别名
public function index(Request $request)
$routeAction = $request->route()->getAction();
print_r($routeAction);
}
输出结果为:
array:8 [▼
"domain" => "www.laravelylw.com"
"middleware" => array:5 [▶]
"as" => "xiong.test"
"uses" => "App\Http\Controllers\Home\Main\XiongTestController@index"
"controller" => "App\Http\Controllers\Home\Main\XiongTestController@index"
"namespace" => "App\Http\Controllers\Home\Main"
"prefix" => null
"where" => []
]
或者使用getName()方法直接获取别名
$request->route()->getName()
或者用
use Illuminate\Routing\Route;
public function index(Request $request,Route $route)
{
echo $route->getName();
}上述就是小编为大家分享的使用laravel怎么获取当前url的别名了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注天达云行业资讯频道。