Skip to content

Commit ccd162c

Browse files
committed
Features attached to menu_arct helper
1 parent a438478 commit ccd162c

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,54 @@ $json_menu = menu_arct('admin', '_json');
9393

9494
![Display Menu](https://raw.githubusercontent.com/rc1021/laravel-menu-architect/master/output_display.png)
9595

96+
## Custom data method
97+
98+
You can customize some methods to use `$menu`, `$menu->items`(relation with menu_id), `$items`(parent-children).
99+
100+
```php
101+
$customize_func = function ($menu)
102+
{
103+
// $menu: main menu modal.
104+
// $menu->items: items by menu_id.
105+
// $menu->buildTree(): get a hierarchical array data.(parent, children)
106+
107+
$collection = collect($menu->items);
108+
$filtered = $collection->filter(function ($item, $key) {
109+
return $item['depth'] == 2 and isset($item['children']);
110+
});
111+
return $filtered->all();
112+
}
113+
114+
$customize_data = menu_arct('admin', 'key', ['key' => $customize_func]);
115+
```
116+
117+
## Output display with custom view
118+
119+
![Custom View](https://raw.githubusercontent.com/rc1021/laravel-menu-architect/master/custom_view.png)
120+
121+
Now, you can add a view to `resources/views/vendor/menu_architect/display` to render menu.
122+
123+
if you have a view called `your_view.blade.php`
124+
125+
```php
126+
// your_view.blade.php
127+
128+
// $menu: main menu modal
129+
// $menu->items: items by menu_id
130+
// $items: Hierarchical array data(parent, children)
131+
132+
<ul class="sidebar-menu tree" data-widget="tree">
133+
@foreach ($items as $item)
134+
<li class="header {{$item['class']}}" style="{{empty($item['color'])?:'color:'.$item['color']}}">{{$item['label']}}</li>
135+
@if(isset($item['children']))
136+
@each('menu_architect::menu.display.adminlte_list', $item['children'], 'item')
137+
@endif
138+
@endforeach
139+
</ul>
140+
```
141+
142+
and you can do `menu_arct('admin', 'your_view')` to render result
143+
96144
## If You Need Help
97145

98146
Please submit all issues and questions using GitHub issues and I will try to help you.

custom_view.png

28.8 KB
Loading

resources/views/menu/index.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
@section('title', 'Menu')
44

5-
@section('content')
5+
@section('content_header')
66
<h1 class="page-title">
77
<i class="glyphicon glyphicon-list"></i> Menus
88
<a href="{{route('menu_arct.create')}}" class="btn btn-success">
99
<i class="glyphicon glyphicon-plus"></i> Add New
1010
</a>
1111
</h1>
12+
@stop
13+
14+
@section('content')
1215

1316
@if(config('menu_architect.tips'))
1417
<div class="alert alert-info">

src/Models/MenuArchitect.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public static function output($menuName, $type = null, array $options = [])
5555
case '_json':
5656
return json_decode(json_encode($menu->buildTree()));
5757
break;
58+
default:
59+
$func = Arr::get($options, $type, false);
60+
if( $func and is_callable( $func ) ) {
61+
return $func($menu);
62+
}
5863
}
5964

6065
if(empty($type))

0 commit comments

Comments
 (0)