如下所示:
?
|
1
2
3
4
|
Route::get('/xiongtest', [
'as' => 'xiong.test',
'uses' => 'XiongTestController@index'
]);
|
以上路由为例
在模版中可以使用route('xiong.test')来获取该路由的真实地址。
在XiongTestController@index中,可以使用以下方法获取路由别名
?
|
1
2
3
4
5
6
7
|
public function index(Request $request)
$routeAction = $request->route()->getAction();
print_r($routeAction);
}
|
输出结果为:
?
|
1
2
3
4
5
6
7
8
9
10
|
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()方法直接获取别名
?
|
1
|
$request->route()->getName()
|
或者用
?
|
1
2
3
4
5
|
use Illuminate\\Routing\\Route;
public function index(Request $request,Route $route)
{
echo $route->getName();
}
|
以上这篇laravel 获取当前url的别名方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。
原文链接:https://blog.csdn.net/xionggang1024/article/details/77195164
相关文章
猜你喜欢
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
搬瓦工VPS服务器CPU性能评估:影响网站速度的关键因素是什么?
2025-06-04 21 -
2025-05-27 34
-
2025-05-29 124
-
2025-05-27 18
-
2025-05-27 40
热门评论

