代码为
//start
use Illuminate\Support\Facades\Route;
public function getRoute()
{
$routes = Route::getRoutes();
foreach ($routes as $route) {
if (!empty($route->action["as"])) {
$controller = !empty($route->action["controller"]) ? explode('\\', $route->action["controller"]) : '';
$data[] = [
'controller' => !empty($controller) ? str_replace('Controller', '', current(explode('@', end($controller)))) : '',
"name" => !empty($route->action["as"]) ? $route->action["as"] : '',
"prefix" => !empty($route->action["prefix"]) ? $route->action["prefix"] : '',
"uri" => $route->uri,
"method" => $route->methods[0],
];
}
}
dd($data);
}
//over
效果为
//start
array:5 [
0 => array:5 [
"controller" => "HealthCheck"
"name" => "ignition.healthCheck"
"prefix" => "_ignition"
"uri" => "_ignition/health-check"
"method" => "GET"
]
1 => array:5 [
"controller" => "ExecuteSolution"
"name" => "ignition.executeSolution"
"prefix" => "_ignition"
"uri" => "_ignition/execute-solution"
"method" => "POST"
]
2 => array:5 [
"controller" => "ShareReport"
"name" => "ignition.shareReport"
"prefix" => "_ignition"
"uri" => "_ignition/share-report"
"method" => "POST"
]
3 => array:5 [
"controller" => "Script"
"name" => "ignition.scripts"
"prefix" => "_ignition"
"uri" => "_ignition/scripts/{script}"
"method" => "GET"
]
4 => array:5 [
"controller" => "Style"
"name" => "ignition.styles"
"prefix" => "_ignition"
"uri" => "_ignition/styles/{style}"
"method" => "GET"
]
]
//over