php - Laravel 4 how get routes by group name -
in laravel, know can routes using `route::getroutes() can't find if possible list of routes contained in specified group.
for example, have route file:
route::group(array('group_name' => 'pages'), function() { route::any('/authentication', array('as' => 'authentication', 'uses' => 'logcontroller@authform' )); route::group(array('before' => 'auth_administration'), function() { route::any('/tags_category/index', array('as' => 'index-tags-categories', 'uses' => 'tagscategorycontroller@index')); route::any('/tags_category/update', array('as' => 'update-tags-category', 'uses' => 'tagscategorycontroller@update')); }); }); route::group(array('before' => 'auth_administration'), function() { route::any('/tags_category/store', array('as' => 'store-tags-category', 'uses' => 'tagscategorycontroller@store')); route::any('/tags_category/update/{id}', array('as' => 'update-form-tags-category', 'uses' => 'tagscategorycontroller@updateform')); route::any('/tags_category/delete/{id}', array('as' => 'delete-tags-category', 'uses' => 'tagscategorycontroller@delete')); }); // operazioni protette
and in controller want obtain routes contained in first group (the 1 variable 'group_name').
is possible? if yes how can it? thanks
the attributes passed group in first parameter stored on route in action
array. array can accessed via getaction()
method on route. so, once access route objects, can filter based on information.
$name = 'pages'; $routecollection = route::getroutes(); // routecollection object $routes = $routecollection->getroutes(); // array of route objects $grouped_routes = array_filter($routes, function($route) use ($name) { $action = $route->getaction(); if (isset($action['group_name'])) { // first level groups, $action['group_name'] string // nested groups, $action['group_name'] array if (is_array($action['group_name'])) { return in_array($name, $action['group_name']); } else { return $action['group_name'] == $name; } } return false; }); // array containing route objects in 'pages' group dd($grouped_routes);
Comments
Post a Comment