Skip to content

Commit a6b02d2

Browse files
committed
Total package reconstruction
1 parent fe64a3e commit a6b02d2

File tree

12 files changed

+295
-155
lines changed

12 files changed

+295
-155
lines changed

ML_menu_en.jpg

43.1 KB
Loading

README.md

Lines changed: 130 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
Laravel MultiMenu widget
2-
==============
1+
# Laravel MultiMenu widget
32

4-
1 Introduction
5-
----------------------------
3+
## 1 Introduction
64

75
[![Latest Stable Version](https://poser.pugx.org/itstructure/laravel-multi-menu/v/stable)](https://packagist.org/packages/itstructure/laravel-multi-menu)
86
[![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
119
[![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)
1210
[![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)
1311

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.
1513

1614
The widget uses data from the **database**, in which there are, in addition to the primary keys, also the parent keys.
1715

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**.
1917

20-
2 Dependencies
21-
----------------------------
18+
![Multi level menu example scheme](https://github.com/itstructure/laravel-multi-menu/blob/master/ML_menu_en.jpg)
2219

23-
- php >= 7.1
20+
## 2 Dependencies
21+
22+
- laravel 5.5+ | 6+ | 7+
23+
- php >= 7.1.0
2424
- composer
2525

26-
3 Installation
27-
----------------------------
26+
## 3 Installation
2827

2928
### 3.1 General from remote repository
3029

3130
Via composer:
3231

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"`
4433

4534
### 3.2 If you are testing this package from local server directory
4635

47-
In application ```composer.json``` file set the repository, like in example:
36+
In application `composer.json` file set the repository, like in example:
4837

49-
```
38+
```json
5039
"repositories": [
5140
{
5241
"type": "path",
@@ -60,104 +49,168 @@ In application ```composer.json``` file set the repository, like in example:
6049

6150
Here,
6251

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.
6453

6554
Then run command:
6655

67-
```composer require itstructure/laravel-multi-menu:dev-master --prefer-source```
56+
`composer require itstructure/laravel-multi-menu:dev-master --prefer-source`
6857

6958
### 3.3 App config
7059

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`
7263

7364
### 3.4 Publish in application
7465

75-
Run command:
66+
- To publish all parts run command:
67+
68+
`php artisan multimenu:publish`
7669

77-
```php artisan vendor:publish --provider="Itstructure\MultiMenu\MultiMenuServiceProvider"```
70+
- To publish only config run command:
7871

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.
8081

81-
### 4.1 Usage in view template
82+
- Else you can use `--force` argument to rewrite already published files.
8283

83-
To run widget in blade view template:
84+
Or another variant:
8485

85-
```blade
86-
{!! app('multiMenuWidget')->run($models, $additionData) !!}
87-
```
86+
`php artisan vendor:publish --provider="Itstructure\MultiMenu\MultiMenuServiceProvider"`
8887

89-
Here,
88+
## 4 Usage
9089

91-
**$models** - must be instance of ```Illuminate\Database\Eloquent\Collection```
90+
### 4.1 Simple variant
9291

93-
**$additionData** - addition cross cutting data for all nesting levels. Can be empty or not defined.
92+
#### Config part
9493

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+
];
98101
```
99102

100-
### 4.2 Config simple
103+
#### View template part
101104

102-
File ```/config/multiMenu.php```:
103105
```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
109110
];
111+
@endphp
112+
```
113+
114+
```php
115+
@multiMenu($multiOptions)
110116
```
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
111121

112-
### 4.3 Config for nesting levels
122+
#### Config part
123+
124+
There is an example to set item blade templates for 3 levels:
113125

114-
File ```/config/multiMenu.php```:
115126
```php
116127
return [
117128
'primaryKeyName' => 'id',
118-
'parentKeyName' => 'parentId',
119-
'mainTemplate' => [
120-
'levels' => [
121-
'main',
122-
'main2'
123-
]
124-
],
129+
'parentKeyName' => 'parent_id',
130+
'mainTemplate' => 'main',
125131
'itemTemplate' => [
126132
'levels' => [
127133
'item',
128-
'item2'
134+
'item',
135+
'item_new',
129136
]
130137
],
131138
];
132139
```
133140

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+
```
135154

136-
```Table "catalogs"```
155+
Example of a custom changed blade template file `item_new.blade`:
137156

138157
```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>
152163
```
153164

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+
154207
## 5 Prevention of collisions
155208

156209
### 5.1 Before save model
157210

158211
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):
159212

160-
Use ```checkNewParentId(Model $mainModel, int $newParentId... e.t.c)```
213+
Use static method `checkNewParentId(Model $mainModel, int $newParentId... e.t.c)`
161214

162215
Here are the required parameters:
163216

@@ -169,17 +222,16 @@ Here are the required parameters:
169222

170223
To prevent breaks in the chain of subject submissions:
171224

172-
Use ```afterDeleteMainModel(Model $mainModel... e.t.c)```
225+
Use static method `afterDeleteMainModel(Model $mainModel... e.t.c)`
173226

174227
Here is the required parameter:
175228

176229
**$mainModel** - deleted model record.
177230

178231
This function will rebuild the chain.
179232

180-
License
181-
----------------------------
233+
## License
182234

183-
Copyright © 2018 Andrey Girnik girnikandrey@gmail.com.
235+
Copyright © 2018-2020 Andrey Girnik girnikandrey@gmail.com.
184236

185237
Licensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### CHANGE LOG:
22

3+
**2.0.0 July 14, 2020:**
4+
- Total package reconstruction.
5+
36
**1.0.2 August 13, 2018:**
47
- Code fixes according with the PSR standards.
58

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"minimum-stability": "dev",
1414
"prefer-stable": true,
1515
"require": {
16-
"laravel/framework": "~5.1.12|~5.2.0|~5.3.0|~5.4.0|~5.5.0|~5.6.0",
16+
"laravel/framework": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0",
1717
"php": ">=7.1.0"
1818
},
1919
"autoload": {

config/multiMenu.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
return [
4-
'primaryKeyName' => 'id',
5-
'parentKeyName' => 'parentId',
6-
'mainTemplate' => 'main',
7-
'itemTemplate' => 'item',
4+
'primaryKeyName' => 'id', // Editable
5+
'parentKeyName' => 'parent_id', // Editable
6+
'mainTemplate' => 'main', // Editable
7+
'itemTemplate' => 'item', // Editable
88
];

resources/views/item.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<li>{!! $data->id !!} need to be changed</li>
1+
<li>
2+
Item Id {!! $data->id !!} {{--Change it--}}
3+
</li>

resources/views/main.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<ul>{!! $items !!}</ul>
1+
<ul>{!! $items !!}</ul> {{--Change it--}}

0 commit comments

Comments
 (0)