|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Eclipse\Cms\Seeders; |
| 4 | + |
| 5 | +use Eclipse\Cms\Models\Menu; |
| 6 | +use Eclipse\Cms\Models\Menu\Item; |
| 7 | +use Eclipse\Cms\Models\Page; |
| 8 | +use Eclipse\Cms\Models\Section; |
| 9 | +use Illuminate\Database\Seeder; |
| 10 | + |
| 11 | +class MenuSeeder extends Seeder |
| 12 | +{ |
| 13 | + public function run(): void |
| 14 | + { |
| 15 | + $this->createMainMenu(); |
| 16 | + $this->createFooterMenu(); |
| 17 | + } |
| 18 | + |
| 19 | + private function getTenantData(): array |
| 20 | + { |
| 21 | + if (config('eclipse-cms.tenancy.enabled')) { |
| 22 | + $tenantModel = config('eclipse-cms.tenancy.model'); |
| 23 | + if ($tenantModel && class_exists($tenantModel)) { |
| 24 | + $tenantFK = config('eclipse-cms.tenancy.foreign_key', 'site_id'); |
| 25 | + |
| 26 | + $tenant = $tenantModel::first(); |
| 27 | + if (! $tenant) { |
| 28 | + $tenant = $tenantModel::create([ |
| 29 | + 'name' => 'Default Site', |
| 30 | + 'domain' => 'localhost', |
| 31 | + ]); |
| 32 | + } |
| 33 | + |
| 34 | + if ($tenant) { |
| 35 | + return [$tenantFK => $tenant->id]; |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + return []; |
| 41 | + } |
| 42 | + |
| 43 | + private function createMainMenu(): void |
| 44 | + { |
| 45 | + $menu = Menu::factory()->create(array_merge([ |
| 46 | + 'title' => [ |
| 47 | + 'en' => 'Main Navigation', |
| 48 | + 'sl' => 'Glavna Navigacija', |
| 49 | + ], |
| 50 | + 'code' => 'main', |
| 51 | + 'is_active' => true, |
| 52 | + ], $this->getTenantData())); |
| 53 | + |
| 54 | + $homeSection = Section::first() ?: Section::factory()->create([ |
| 55 | + 'name' => [ |
| 56 | + 'en' => 'Home', |
| 57 | + 'sl' => 'Domov', |
| 58 | + ], |
| 59 | + ]); |
| 60 | + |
| 61 | + $aboutSection = Section::first() ?: Section::factory()->create([ |
| 62 | + 'name' => [ |
| 63 | + 'en' => 'About', |
| 64 | + 'sl' => 'O nas', |
| 65 | + ], |
| 66 | + ]); |
| 67 | + |
| 68 | + $homeItem = Item::factory()->linkableToSection()->create([ |
| 69 | + 'label' => [ |
| 70 | + 'en' => 'Home', |
| 71 | + 'sl' => 'Domov', |
| 72 | + ], |
| 73 | + 'menu_id' => $menu->id, |
| 74 | + 'linkable_id' => $homeSection->id, |
| 75 | + 'is_active' => true, |
| 76 | + 'sort' => 1, |
| 77 | + ]); |
| 78 | + |
| 79 | + $aboutItem = Item::factory()->linkableToSection()->create([ |
| 80 | + 'label' => [ |
| 81 | + 'en' => 'About Us', |
| 82 | + 'sl' => 'O nas', |
| 83 | + ], |
| 84 | + 'menu_id' => $menu->id, |
| 85 | + 'linkable_id' => $aboutSection->id, |
| 86 | + 'is_active' => true, |
| 87 | + 'sort' => 2, |
| 88 | + ]); |
| 89 | + |
| 90 | + $servicesGroup = Item::factory()->group()->create([ |
| 91 | + 'label' => [ |
| 92 | + 'en' => 'Our Services', |
| 93 | + 'sl' => 'Naše Storitve', |
| 94 | + ], |
| 95 | + 'menu_id' => $menu->id, |
| 96 | + 'is_active' => true, |
| 97 | + 'sort' => 3, |
| 98 | + ]); |
| 99 | + |
| 100 | + if (Page::count() > 0) { |
| 101 | + $servicePage = Page::first(); |
| 102 | + Item::factory()->linkableToPage()->childOf($servicesGroup)->create([ |
| 103 | + 'label' => [ |
| 104 | + 'en' => 'Web Development Services', |
| 105 | + 'sl' => 'Storitve Spletnega Razvoja', |
| 106 | + ], |
| 107 | + 'linkable_id' => $servicePage->id, |
| 108 | + 'is_active' => true, |
| 109 | + 'sort' => 1, |
| 110 | + ]); |
| 111 | + } |
| 112 | + |
| 113 | + Item::factory()->customUrl('https://support.example.com')->childOf($servicesGroup)->create([ |
| 114 | + 'label' => [ |
| 115 | + 'en' => 'Customer Support', |
| 116 | + 'sl' => 'Podpora Strankam', |
| 117 | + ], |
| 118 | + 'new_tab' => true, |
| 119 | + 'is_active' => true, |
| 120 | + 'sort' => 2, |
| 121 | + ]); |
| 122 | + |
| 123 | + Item::factory()->customUrl('/contact')->create([ |
| 124 | + 'label' => [ |
| 125 | + 'en' => 'Contact Us', |
| 126 | + 'sl' => 'Kontakt', |
| 127 | + ], |
| 128 | + 'menu_id' => $menu->id, |
| 129 | + 'is_active' => true, |
| 130 | + 'sort' => 4, |
| 131 | + ]); |
| 132 | + } |
| 133 | + |
| 134 | + private function createFooterMenu(): void |
| 135 | + { |
| 136 | + $menu = Menu::factory()->create(array_merge([ |
| 137 | + 'title' => [ |
| 138 | + 'en' => 'Footer Links', |
| 139 | + 'sl' => 'Povezave v Nogi', |
| 140 | + ], |
| 141 | + 'code' => 'footer', |
| 142 | + 'is_active' => true, |
| 143 | + ], $this->getTenantData())); |
| 144 | + |
| 145 | + Item::factory()->customUrl('/privacy')->create([ |
| 146 | + 'label' => [ |
| 147 | + 'en' => 'Privacy Policy', |
| 148 | + 'sl' => 'Pravilnik o Zasebnosti', |
| 149 | + ], |
| 150 | + 'menu_id' => $menu->id, |
| 151 | + 'is_active' => true, |
| 152 | + 'sort' => 1, |
| 153 | + ]); |
| 154 | + |
| 155 | + Item::factory()->customUrl('/terms')->create([ |
| 156 | + 'label' => [ |
| 157 | + 'en' => 'Terms of Service', |
| 158 | + 'sl' => 'Pogoji Uporabe', |
| 159 | + ], |
| 160 | + 'menu_id' => $menu->id, |
| 161 | + 'is_active' => true, |
| 162 | + 'sort' => 2, |
| 163 | + ]); |
| 164 | + |
| 165 | + if (Section::count() > 1) { |
| 166 | + $section = Section::skip(1)->first(); |
| 167 | + Item::factory()->linkableToSection()->create([ |
| 168 | + 'label' => [ |
| 169 | + 'en' => 'Latest News', |
| 170 | + 'sl' => 'Najnovice', |
| 171 | + ], |
| 172 | + 'menu_id' => $menu->id, |
| 173 | + 'linkable_id' => $section->id, |
| 174 | + 'is_active' => true, |
| 175 | + 'sort' => 3, |
| 176 | + ]); |
| 177 | + } |
| 178 | + } |
| 179 | +} |
0 commit comments