我在" App \ Htpp \ Controllers"中的Panel名称空间下有控制器。目录, 所以我的命名空间是:App \ Http \ Controllers \ Panel
我覆盖了如下所示的routeScans()函数,但没有帮助!
public function routeScans() {
$classes = parent::routeScans();
$classes = array_merge(
$classes,
$this->getClassesFromNamespace('App\Http\Controllers\Panel')
);
return $classes;
}
如何扫描路线?
答案 0 :(得分:0)
我创建了一个列出所有可用路线的功能,您可以根据需要使用它并进行修改
function routelist () {
$allRoutes = Route::getRoutes()->getRoutes();
$availableRoutes = [];
foreach ($allRoutes as $route) {
$availableRoutes['availableAPI'][$route->getName()] = [
'method' => $route->getMethods()[0],
"uri" => $route->getUri(),
"name" => $route->getName(),
"controller" => $route->getAction()['uses'],
];
}
$table = "<table>";
foreach ($availableRoutes['availableAPI'] as $key => $entry) {
//dd($entry['controller']);
$table .= "<tr>";
$table .= "<td>" . @$entry['method'] . "</td>";
$table .= "<td>" . @$entry['uri'] . "</td>";
$table .= "<td>" . @$entry['name'] . "</td>";
if (is_string($entry['controller'])) {
$table .= "<td>" . @$entry['controller'] . "</td>";
} else {
$table .= "<td>closure function(){}</td>";
}
$table .= "</tr>";
}
$table .= "</table>";
return $table;
}