betterde / tree
Tree generator
Fund package maintenance!
betterde.github.io/ects/introduction/more.html
v1.0.8
2020-06-13 02:49 UTC
Requires
- illuminate/database: ^5|^6|^7
- illuminate/support: ^5|^6|^7
README
use Betterde\Tree\Generator;
$menus = [
[
'id' => 1,
'parent_id' => 0,
'label' => 'Dashboard',
'link' => '/dashboard',
'icon' => null,
'roles' => 'Admin,'
],
[
'id' => 2,
'parent_id' => 1,
'label' => 'Fiance',
'link' => '/dashboard/finace',
'icon' => null,
'roles' => 'Admin,Fiance'
],
[
'id' => 3,
'parent_id' => 1,
'label' => 'Operation',
'link' => '/dashboard/operation',
'icon' => null,
'roles' => 'Admin,Operation'
],
];
$generator = new Generator();
$tree = $generator->make($menus, 'id', 'parent_id', 'sub_menus', 0);
Generated result
[ [ 'id' => 1, 'parent_id' => 0, 'label' => 'Dashboard', 'link' => '/dashboard', 'icon' => null, 'roles' => 'Admin,', 'sub_menus' => [ [ 'id' => 2, 'parent_id' => 1, 'label' => 'Fiance', 'link' => '/dashboard/finace', 'icon' => null, 'roles' => 'Admin,Fiance' ], [ 'id' => 3, 'parent_id' => 1, 'label' => 'Operation', 'link' => '/dashboard/operation', 'icon' => null, 'roles' => 'Admin,Operation' ] ] ] ];