获取laravel的route列表

521次阅读
没有评论

代码为

//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

 

 

李路昌
版权声明:本站原创文章,由 李路昌 2022-12-24发表,共计1273字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)