laravel 获取当前url的别名方法

2025-05-27 0 77

如下所示:

?

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

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 laravel 获取当前url的别名方法 https://www.kuaiidc.com/71085.html

相关文章

发表评论
暂无评论