Skip to content

Commit 8b711df

Browse files
committed
Added Dynamnic nested menu
1 parent ab345e5 commit 8b711df

File tree

19 files changed

+366
-145105
lines changed

19 files changed

+366
-145105
lines changed

database/migrations/2019_08_27_165403_create_menu_items_table.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public function up()
2222
$table->string('target')->default('_self');
2323
$table->integer('parent_id')->unsigned()->nullable();
2424
$table->integer('order')->unsigned()->default(0);
25+
$table->string('route')->nullable();
26+
$table->text('params')->nullable();
27+
$table->string('controller')->nullable();
28+
$table->string('middleware')->nullable();
2529
$table->string('icon')->nullable();
2630
$table->string('custom_class')->nullable();
2731
$table->timestamps();

database/seeds/DatabaseManagerSeeder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function run()
1515
{
1616
$seeds = [
1717
'DatabasePermissionSeeder',
18+
'DatabaseMenuSeeder',
1819
];
1920

2021
foreach ($seeds as $class) {

database/seeds/DatabaseMenuSeeder.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
use CodexShaper\DBM\Facades\Manager as DBM;
4+
use Illuminate\Database\Seeder;
5+
6+
class DatabaseMenuSeeder extends Seeder
7+
{
8+
/**
9+
* Run the database seeds.
10+
*
11+
* @return void
12+
*/
13+
public function run()
14+
{
15+
$menu = DBM::Menu()->where('slug','admin')->first();
16+
17+
if(! $menu) {
18+
$order = DBM::Menu()->max('order');
19+
$menu = DBM::Menu();
20+
$menu->name = "Admin";
21+
$menu->slug = Str::slug('Admin');
22+
$menu->url = '/admin';
23+
$menu->order = $order+1;
24+
$menu->save();
25+
}
26+
27+
foreach($this->getItems() as $item) {
28+
if(! DBM::MenuItem()->where('slug', Str::slug($item['slug']))->first()) {
29+
$itemOrder = DBM::MenuItem()->max('order');
30+
$menuItem = DBM::MenuItem();
31+
$menuItem->menu_id = $menu->id;
32+
$menuItem->title = $item['title'];
33+
$menuItem->slug = Str::slug($item['slug']);
34+
$menuItem->url = $item['url'];
35+
if($item['parent']) {
36+
$parentItem = DBM::MenuItem()->where('slug', $item['parent'])->first();
37+
$menuItem->parent_id = $parentItem->id;
38+
}
39+
$menuItem->order = $itemOrder+1;
40+
$menuItem->route = $item['route'];
41+
$menuItem->params = $item['params'];
42+
$menuItem->middleware = $item['middleware'];
43+
$menuItem->controller = $item['controller'];
44+
$menuItem->target = $item['target'];
45+
$menuItem->icon = $item['icon'];
46+
$menuItem->custom_class = $item['custom_class'];
47+
$menuItem->save();
48+
}
49+
}
50+
}
51+
52+
public function getItems()
53+
{
54+
[
55+
'database' => [
56+
'title' => 'Database',
57+
'slug' => 'database',
58+
'url' => '/database',
59+
'parent' => null,
60+
'route' => null,
61+
'params' => null,
62+
'controller' => null,
63+
'middleware' => null,
64+
'target' => '_self',
65+
'icon' => '<i class="fas fa-database"></i>',
66+
'custom_class' => null,
67+
],
68+
'table' => [
69+
'title' => 'Table',
70+
'slug' => 'table',
71+
'url' => '/database',
72+
'parent' => 'database',
73+
'route' => 'database',
74+
'params' => null,
75+
'controller' => null,
76+
'middleware' => null,
77+
'target' => '_self',
78+
'icon' => '<i class="fas fa-table"></i>',
79+
'custom_class' => null,
80+
],
81+
'crud' => [
82+
'title' => 'Crud',
83+
'slug' => 'crud',
84+
'url' => '/database/crud',
85+
'parent' => 'database',
86+
'route' => 'crud',
87+
'params' => null,
88+
'controller' => null,
89+
'middleware' => null,
90+
'target' => '_self',
91+
'icon' => '<i class="fas fa-database"></i>',
92+
'custom_class' => null,
93+
],
94+
'permission' => [
95+
'title' => 'Permission',
96+
'slug' => 'permission',
97+
'url' => '/permission',
98+
'parent' => 'database',
99+
'route' => 'permission',
100+
'params' => null,
101+
'controller' => null,
102+
'middleware' => null,
103+
'target' => '_self',
104+
'icon' => '<i class="fas fa-user-lock"></i>',
105+
'custom_class' => null,
106+
],
107+
'backup' => [
108+
'title' => 'Backup',
109+
'slug' => 'backup',
110+
'url' => '/database',
111+
'parent' => 'database',
112+
'route' => 'backup',
113+
'params' => null,
114+
'controller' => null,
115+
'middleware' => null,
116+
'target' => '_self',
117+
'icon' => '<i class="fas fa-sync"></i>',
118+
'custom_class' => null,
119+
],
120+
];
121+
}
122+
}

0 commit comments

Comments
 (0)