1
- Laravel MultiMenu widget
2
- ==============
1
+ # Laravel MultiMenu widget
3
2
4
- 1 Introduction
5
- ----------------------------
3
+ ## 1 Introduction
6
4
7
5
[ ![ Latest Stable Version] ( https://poser.pugx.org/itstructure/laravel-multi-menu/v/stable )] ( https://packagist.org/packages/itstructure/laravel-multi-menu )
8
6
[ ![ Latest Unstable Version] ( https://poser.pugx.org/itstructure/laravel-multi-menu/v/unstable )] ( https://packagist.org/packages/itstructure/laravel-multi-menu )
@@ -11,42 +9,33 @@ Laravel MultiMenu widget
11
9
[ ![ Build Status] ( https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/badges/build.png?b=master )] ( https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/build-status/master )
12
10
[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/?branch=master )
13
11
14
- This widget is to display a multi level menu. There can be nested submenus . Used for Laravel framework.
12
+ This widget is to display a multi level menu. There can be nested sub-menus . Used for Laravel framework.
15
13
16
14
The widget uses data from the ** database** , in which there are, in addition to the primary keys, also the parent keys.
17
15
18
- Data from the ** database** is taken from a model, which instance of ** Illuminate\Database\Eloquent\Model ** .
16
+ Data from the ** database** is taken from a model and must be instance of ** Illuminate\Database\Eloquent\Collection ** .
19
17
20
- 2 Dependencies
21
- ----------------------------
18
+ ![ Multi level menu example scheme] ( https://github.com/itstructure/laravel-multi-menu/blob/master/ML_menu_en.jpg )
22
19
23
- - php >= 7.1
20
+ ## 2 Dependencies
21
+
22
+ - laravel 5.5+ | 6+ | 7+
23
+ - php >= 7.1.0
24
24
- composer
25
25
26
- 3 Installation
27
- ----------------------------
26
+ ## 3 Installation
28
27
29
28
### 3.1 General from remote repository
30
29
31
30
Via composer:
32
31
33
- ``` composer require "itstructure/laravel-multi-menu": "^1.0.2" ```
34
-
35
- or in section ** require** of composer.json file set the following:
36
- ```
37
- "require": {
38
- "itstructure/laravel-multi-menu": "^1.0.2"
39
- }
40
- ```
41
- and command ``` composer install ``` , if you install laravel project extensions first,
42
-
43
- or command ``` composer update ``` , if all laravel project extensions are already installed.
32
+ ` composer require itstructure/laravel-multi-menu "~2.0.0" `
44
33
45
34
### 3.2 If you are testing this package from local server directory
46
35
47
- In application ``` composer.json `` ` file set the repository, like in example:
36
+ In application ` composer.json ` file set the repository, like in example:
48
37
49
- ```
38
+ ``` json
50
39
"repositories" : [
51
40
{
52
41
"type" : " path" ,
@@ -60,104 +49,168 @@ In application ```composer.json``` file set the repository, like in example:
60
49
61
50
Here,
62
51
63
- ** laravel-multi-menu** - directory name, which hase the same directory level like application and contains multi menu package.
52
+ ** ../ laravel-multi-menu** - directory name, which has the same directory level as application and contains multi menu package.
64
53
65
54
Then run command:
66
55
67
- ``` composer require itstructure/laravel-multi-menu:dev-master --prefer-source `` `
56
+ ` composer require itstructure/laravel-multi-menu:dev-master --prefer-source `
68
57
69
58
### 3.3 App config
70
59
71
- Add to application ``` config/app.php ``` file to section ** providers** : ``` Itstructure\MultiMenu\MultiMenuServiceProvider::class ```
60
+ Add to application ` config/app.php ` file to section ** providers** :
61
+
62
+ ` Itstructure\MultiMenu\MultiMenuServiceProvider::class `
72
63
73
64
### 3.4 Publish in application
74
65
75
- Run command:
66
+ - To publish all parts run command:
67
+
68
+ ` php artisan multimenu:publish `
76
69
77
- ``` php artisan vendor: publish --provider="Itstructure\MultiMenu\MultiMenuServiceProvider" ```
70
+ - To publish only config run command:
78
71
79
- ## 4 Usage
72
+ ` php artisan multimenu:publish --only=config `
73
+
74
+ It stores ` multimenu.php ` config file to ` config ` folder.
75
+
76
+ - To publish only views run command:
77
+
78
+ ` php artisan multimenu:publish --only=views `
79
+
80
+ It stores view files to ` resources/views/vendor/multimenu ` folder.
80
81
81
- ### 4.1 Usage in view template
82
+ - Else you can use ` --force ` argument to rewrite already published files.
82
83
83
- To run widget in blade view template :
84
+ Or another variant :
84
85
85
- ``` blade
86
- {!! app('multiMenuWidget')->run($models, $additionData) !!}
87
- ```
86
+ ` php artisan vendor:publish --provider="Itstructure\MultiMenu\MultiMenuServiceProvider" `
88
87
89
- Here,
88
+ ## 4 Usage
90
89
91
- ** $models ** - must be instance of ``` Illuminate\Database\Eloquent\Collection ```
90
+ ### 4.1 Simple variant
92
91
93
- ** $additionData ** - addition cross cutting data for all nesting levels. Can be empty or not defined.
92
+ #### Config part
94
93
95
- Example of custom changed view ``` item.blade ``` :
96
- ``` html
97
- <li ><a href =" /catalog/{!! $data->id !!}" >{!! $data->title !!}</a ></li >
94
+ ``` php
95
+ return [
96
+ 'primaryKeyName' => 'id', // Editable
97
+ 'parentKeyName' => 'parent_id', // Editable
98
+ 'mainTemplate' => 'main', // Editable
99
+ 'itemTemplate' => 'item', // Editable
100
+ ];
98
101
```
99
102
100
- ### 4.2 Config simple
103
+ #### View template part
101
104
102
- File ``` /config/multiMenu.php ``` :
103
105
``` php
104
- return [
105
- 'primaryKeyName' => 'id',
106
- 'parentKeyName' => 'parentId',
107
- 'mainTemplate' => 'main',
108
- 'itemTemplate' => 'item',
106
+ @php
107
+ $multiOptions = [ // Editable
108
+ 'config' => config('multimenu'),
109
+ 'data' => $pages
109
110
];
111
+ @endphp
112
+ ```
113
+
114
+ ``` php
115
+ @multiMenu($multiOptions)
110
116
```
117
+
118
+ Here, ` $pages ` - is from controller part, for example ` $pages = Page::all(); ` . Must be instance of ` Illuminate\Database\Eloquent\Collection ` .
119
+
120
+ ### 4.2 Addition config options and data
111
121
112
- ### 4.3 Config for nesting levels
122
+ #### Config part
123
+
124
+ There is an example to set item blade templates for 3 levels:
113
125
114
- File ``` /config/multiMenu.php ``` :
115
126
``` php
116
127
return [
117
128
'primaryKeyName' => 'id',
118
- 'parentKeyName' => 'parentId',
119
- 'mainTemplate' => [
120
- 'levels' => [
121
- 'main',
122
- 'main2'
123
- ]
124
- ],
129
+ 'parentKeyName' => 'parent_id',
130
+ 'mainTemplate' => 'main',
125
131
'itemTemplate' => [
126
132
'levels' => [
127
133
'item',
128
- 'item2'
134
+ 'item',
135
+ 'item_new',
129
136
]
130
137
],
131
138
];
132
139
```
133
140
134
- ### 4.4 Database table structure example
141
+ You can set ` mainTemplate ` by analogy.
142
+
143
+ #### Blade templates
144
+
145
+ Example of a custom changed blade template file ` item.blade ` :
146
+
147
+ ``` php
148
+ <li >
149
+ <a href =" {{ $data->icon }}" >
150
+ Initial item Id {{ $data->id }} {{ isset($addition) ? ' | ' . $addition : '' }}
151
+ </a >
152
+ </li >
153
+ ```
135
154
136
- ``` Table "catalogs" ```
155
+ Example of a custom changed blade template file ` item_new.blade ` :
137
156
138
157
``` php
139
- | id | parentId | title | ... |
140
- |-----|----------|----------|-----|
141
- | 1 | NULL | catalog1 | ... |
142
- | 2 | NULL | catalog2 | ... |
143
- | 3 | 1 | catalog3 | ... |
144
- | 4 | 1 | catalog4 | ... |
145
- | 5 | 4 | catalog5 | ... |
146
- | 6 | 4 | catalog6 | ... |
147
- | 7 | 3 | catalog7 | ... |
148
- | 8 | 3 | catalog8 | ... |
149
- | 9 | NULL | catalog9 | ... |
150
- | 10 | NULL | catalog10| ... |
151
- | ... | ... | ... | ... |
158
+ <li >
159
+ <a href =" {{ $data->icon }}" style =" color : green ; font-weight : bold ;" >
160
+ New item Id {{ $data->id }} {{ isset($addition) ? ' | ' . $addition : '' }}
161
+ </a >
162
+ </li >
152
163
```
153
164
165
+ #### Addition data
166
+
167
+ Example in a template file:
168
+
169
+ ``` php
170
+ @php
171
+ $multiOptions = [
172
+ 'config' => config('multimenu'),
173
+ 'data' => $pages,
174
+ 'additionData' => [
175
+ 'levels' => [
176
+ 0 => [],
177
+ 1 => ['addition' => 'addition string']
178
+ ]
179
+ ]
180
+ ];
181
+ @endphp
182
+ ```
183
+
184
+ ``` php
185
+ @multiMenu($multiOptions)
186
+ ```
187
+
188
+ ### 4.3 Database table structure example
189
+
190
+ ` Table "catalogs" `
191
+
192
+ | id | parent_id | title | ... |
193
+ |-----|-----------|------------|-----|
194
+ | 1 | NULL | item 1 | ... |
195
+ | 2 | NULL | item 2 | ... |
196
+ | 3 | NULL | item 3 | ... |
197
+ | 4 | NULL | item 4 | ... |
198
+ | 5 | NULL | item 5 | ... |
199
+ | 6 | 2 | item 2.1 | ... |
200
+ | 7 | 2 | item 2.2 | ... |
201
+ | 8 | 7 | item 2.2.1 | ... |
202
+ | 9 | 7 | item 2.2.2 | ... |
203
+ | 10 | 7 | item 2.2.3 | ... |
204
+ | ... | ... | ... | ... |
205
+
206
+
154
207
## 5 Prevention of collisions
155
208
156
209
### 5.1 Before save model
157
210
158
211
To prevent the entry of the wrong parent identifier (for example, the new number that is a child in a subordinate chain of nested records):
159
212
160
- Use ``` checkNewParentId(Model $mainModel, int $newParentId... e.t.c) `` `
213
+ Use static method ` checkNewParentId(Model $mainModel, int $newParentId... e.t.c) `
161
214
162
215
Here are the required parameters:
163
216
@@ -169,17 +222,16 @@ Here are the required parameters:
169
222
170
223
To prevent breaks in the chain of subject submissions:
171
224
172
- Use ``` afterDeleteMainModel(Model $mainModel... e.t.c) `` `
225
+ Use static method ` afterDeleteMainModel(Model $mainModel... e.t.c) `
173
226
174
227
Here is the required parameter:
175
228
176
229
** $mainModel** - deleted model record.
177
230
178
231
This function will rebuild the chain.
179
232
180
- License
181
- ----------------------------
233
+ ## License
182
234
183
- Copyright © 2018 Andrey Girnik girnikandrey@gmail.com .
235
+ Copyright © 2018-2020 Andrey Girnik girnikandrey@gmail.com .
184
236
185
237
Licensed under the [ MIT license] ( http://opensource.org/licenses/MIT ) . See LICENSE.txt for details.
0 commit comments