如何在laravel中获得所有公共路线

时间:2017-02-27 05:51:42

标签: laravel laravel-5.4

如何仅获取所有公共路线

  Route::getRoutes()

获取所有路线,但只需要公共路线

1 个答案:

答案 0 :(得分:1)

没有确切的方法可以做到这一点,因为“公共”的概念取决于您的具体实施。什么是“公共”?它是没有某些中间件等的路线吗?

根据您的要求,扩展以下功能将起作用:

// loop over each route, and if it has 1 or more middleware's, 
// reject it, leaving you with just the "public" routes
// You can change the condition to what is public
// very easily
$routesWithoutMiddleware = collect(Route::getRoutes())->reject(function($route) {
    return count($route->middleware()) > 0;
});