Skip to content

Commit e12f4a1

Browse files
authored
Merge branch 'main' into feat/banners
2 parents d443dd7 + a959f8f commit e12f4a1

28 files changed

Lines changed: 2448 additions & 8 deletions

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"filament/filament": "^3.3",
4949
"filament/spatie-laravel-translatable-plugin": "^3.3",
5050
"spatie/image": "^3.8",
51+
"solution-forest/filament-tree": "^2.1",
5152
"spatie/laravel-package-tools": "^1.19"
5253
},
5354
"require-dev": {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('cms_menus', function (Blueprint $table) {
12+
$table->id();
13+
14+
if (config('eclipse-cms.tenancy.enabled')) {
15+
$tenantClass = config('eclipse-cms.tenancy.model');
16+
/** @var \Illuminate\Database\Eloquent\Model $tenant */
17+
$tenant = new $tenantClass;
18+
$table->foreignId(config('eclipse-cms.tenancy.foreign_key'))
19+
->constrained($tenant->getTable(), $tenant->getKeyName())
20+
->cascadeOnUpdate()
21+
->cascadeOnDelete();
22+
}
23+
24+
$table->string('title');
25+
$table->boolean('is_active')->default(true);
26+
$table->string('code')->nullable();
27+
$table->timestamps();
28+
$table->softDeletes();
29+
});
30+
}
31+
32+
public function down(): void
33+
{
34+
Schema::dropIfExists('cms_menus');
35+
}
36+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('cms_menu_items', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('label');
14+
$table->foreignId('menu_id')
15+
->constrained('cms_menus', 'id')
16+
->cascadeOnUpdate()
17+
->cascadeOnDelete();
18+
$table->integer('parent_id')->default(-1);
19+
$table->string('type');
20+
$table->string('linkable_class')->nullable();
21+
$table->string('linkable_id')->nullable();
22+
$table->text('custom_url')->nullable();
23+
$table->boolean('new_tab')->default(false);
24+
$table->boolean('is_active')->default(true);
25+
$table->integer('sort')->default(0);
26+
$table->timestamps();
27+
$table->softDeletes();
28+
});
29+
}
30+
31+
public function down(): void
32+
{
33+
Schema::dropIfExists('cms_menu_items');
34+
}
35+
};

database/seeders/CmsSeeder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function run(): void
1414
->create();
1515

1616
$this
17-
->call(BannerSeeder::class);
17+
->call(BannerSeeder::class)
18+
->call(MenuSeeder::class);
1819
}
1920
}

database/seeders/MenuSeeder.php

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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

Comments
 (0)