laravel中的路由

持续整理一些laravel中获取路由相关信息的方法

Request类

Request::url() 或者 $request->url()

获取当前请求的完整路径

Request::path() 或 $request->path()

Request::getRequestUri() 或 $request->getRequestUri()

Request::getUri() 或 $request->getUri()

$request->route()->getAction()

打印得到如下信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
array:14 [
"version" => array:1 [
0 => "v1"
]
"middleware" => array:2 [
0 => "api.controllers"
1 => "upload.file"
]
"providers" => []
"scopes" => []
"before" => []
"after" => []
"domain" => "api.ics.com"
"conditionalRequest" => true
"as" => "uploadAvatar"
"uses" => "App\Http\Controllers\Api\UsersController@editAvatar"
"namespace" => "App\Http\Controllers\Api"
"prefix" => ""
"where" => []
"uri" => "/uploadAvatar"
]

Request::server() 或 $request->server()

可以获取到$_SERVER数组的信息

坚持原创技术分享,您的支持将鼓励我继续创作!