1
你好我正在嘗試這樣做,但它得到所有的路線,我只想要來自特定組的路線。如何通過laravel 5中的特定組獲取路由列表?
這是我的代碼:
<?php
$routes = Routes::getRoutes();
@foreach($routes as $route)
{{ $route->getPath() }}
@endforeach`
在此先感謝!
你好我正在嘗試這樣做,但它得到所有的路線,我只想要來自特定組的路線。如何通過laravel 5中的特定組獲取路由列表?
這是我的代碼:
<?php
$routes = Routes::getRoutes();
@foreach($routes as $route)
{{ $route->getPath() }}
@endforeach`
在此先感謝!
// 讓我們有一些路線的,沒有任何團體
Route::get('/', function() {
return view('welcome');
});
Route::get('/load', '[email protected]');
// 現在創建組
Route::group(['as' => 'admin'], function() {
Route::get('users', function() {
return "users route";
});
Route::get('ravi', function() {
return "ravi route";
});
// 一些航線現在,我們要創建一個路由在這個組中,它將尋找 //管理組,並打印所有路由與這個組。
Route::get('kumar', function() {
$name = 'admin';
$routeCollection = Route::getRoutes(); // RouteCollection object
$routes = $routeCollection->getRoutes(); // array of route objects
// 現在在我們的路由對象,我們將看看我們命名的路由通過過濾 //數組。
$grouped_routes = array_filter($routes, function($route) use ($name) {
$action = $route->getAction(); // getting route action
if (isset($action['as'])) {
// for the first level groups, $action['as']
//will be a string
// for nested groups, $action['as'] will be an array
if (is_array($action['as'])) {
return in_array($name, $action['as']);
} else {
return $action['as'] == $name;
}
}
return false;
});
// let's print the array containing the route objects in the 'admin' group
dd($grouped_routes);
});
});
// **只需複製並粘貼到你的路線文件夾,你可以通過敲擊your_project_public_folder_url /庫馬爾**
看到輸出//我把幫助從這個答案Answer of patricus
請舉例 –
例如:我在我的表中有一個權限命名列,其中我將存儲一些與特定路由組相關的特定路由。 –