Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"datalinx/php-utils": "^2.5",
"eclipsephp/common": "dev-main",
"filament/filament": "^3.3",
"filament/spatie-laravel-translatable-plugin": "^3.3",
"solution-forest/filament-tree": "^2.1",
"spatie/laravel-package-tools": "^1.19"
},
"require-dev": {
Expand Down
36 changes: 36 additions & 0 deletions database/migrations/2025_07_28_083630_create_menus_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('cms_menus', function (Blueprint $table) {
$table->id();

if (config('eclipse-cms.tenancy.enabled')) {
$tenantClass = config('eclipse-cms.tenancy.model');
/** @var \Illuminate\Database\Eloquent\Model $tenant */
$tenant = new $tenantClass;
$table->foreignId(config('eclipse-cms.tenancy.foreign_key'))
->constrained($tenant->getTable(), $tenant->getKeyName())
->cascadeOnUpdate()
->cascadeOnDelete();
}

$table->string('title');
$table->boolean('is_active')->default(true);
$table->string('code')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

public function down(): void
{
Schema::dropIfExists('cms_menus');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('cms_menu_items', function (Blueprint $table) {
$table->id();
$table->string('label');
$table->foreignId('menu_id')
->constrained('cms_menus', 'id')
->cascadeOnUpdate()
->cascadeOnDelete();
$table->integer('parent_id')->default(-1);
$table->string('type');
$table->string('linkable_class')->nullable();
$table->string('linkable_id')->nullable();
$table->text('custom_url')->nullable();
$table->boolean('new_tab')->default(false);
$table->boolean('is_active')->default(true);
$table->integer('sort')->default(0);
$table->timestamps();
$table->softDeletes();
});
}

public function down(): void
{
Schema::dropIfExists('cms_menu_items');
}
};
2 changes: 2 additions & 0 deletions database/seeders/CmsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public function run(): void
Section::factory()
->count(3)
->create();

$this->call(MenuSeeder::class);
}
}
179 changes: 179 additions & 0 deletions database/seeders/MenuSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace Eclipse\Cms\Seeders;

use Eclipse\Cms\Models\Menu;
use Eclipse\Cms\Models\Menu\Item;
use Eclipse\Cms\Models\Page;
use Eclipse\Cms\Models\Section;
use Illuminate\Database\Seeder;

class MenuSeeder extends Seeder
{
public function run(): void
{
$this->createMainMenu();
$this->createFooterMenu();
}

private function getTenantData(): array
{
if (config('eclipse-cms.tenancy.enabled')) {
$tenantModel = config('eclipse-cms.tenancy.model');
if ($tenantModel && class_exists($tenantModel)) {
$tenantFK = config('eclipse-cms.tenancy.foreign_key', 'site_id');

$tenant = $tenantModel::first();
if (! $tenant) {
$tenant = $tenantModel::create([
'name' => 'Default Site',
'domain' => 'localhost',
]);
}

if ($tenant) {
return [$tenantFK => $tenant->id];
}
}
}

return [];
}

private function createMainMenu(): void
{
$menu = Menu::factory()->create(array_merge([
'title' => [
'en' => 'Main Navigation',
'sl' => 'Glavna Navigacija',
],
'code' => 'main',
'is_active' => true,
], $this->getTenantData()));

$homeSection = Section::first() ?: Section::factory()->create([
'name' => [
'en' => 'Home',
'sl' => 'Domov',
],
]);

$aboutSection = Section::first() ?: Section::factory()->create([
'name' => [
'en' => 'About',
'sl' => 'O nas',
],
]);

$homeItem = Item::factory()->linkableToSection()->create([
'label' => [
'en' => 'Home',
'sl' => 'Domov',
],
'menu_id' => $menu->id,
'linkable_id' => $homeSection->id,
'is_active' => true,
'sort' => 1,
]);

$aboutItem = Item::factory()->linkableToSection()->create([
'label' => [
'en' => 'About Us',
'sl' => 'O nas',
],
'menu_id' => $menu->id,
'linkable_id' => $aboutSection->id,
'is_active' => true,
'sort' => 2,
]);

$servicesGroup = Item::factory()->group()->create([
'label' => [
'en' => 'Our Services',
'sl' => 'Naše Storitve',
],
'menu_id' => $menu->id,
'is_active' => true,
'sort' => 3,
]);

if (Page::count() > 0) {
$servicePage = Page::first();
Item::factory()->linkableToPage()->childOf($servicesGroup)->create([
'label' => [
'en' => 'Web Development Services',
'sl' => 'Storitve Spletnega Razvoja',
],
'linkable_id' => $servicePage->id,
'is_active' => true,
'sort' => 1,
]);
}

Item::factory()->customUrl('https://support.example.com')->childOf($servicesGroup)->create([
'label' => [
'en' => 'Customer Support',
'sl' => 'Podpora Strankam',
],
'new_tab' => true,
'is_active' => true,
'sort' => 2,
]);

Item::factory()->customUrl('/contact')->create([
'label' => [
'en' => 'Contact Us',
'sl' => 'Kontakt',
],
'menu_id' => $menu->id,
'is_active' => true,
'sort' => 4,
]);
}

private function createFooterMenu(): void
{
$menu = Menu::factory()->create(array_merge([
'title' => [
'en' => 'Footer Links',
'sl' => 'Povezave v Nogi',
],
'code' => 'footer',
'is_active' => true,
], $this->getTenantData()));

Item::factory()->customUrl('/privacy')->create([
'label' => [
'en' => 'Privacy Policy',
'sl' => 'Pravilnik o Zasebnosti',
],
'menu_id' => $menu->id,
'is_active' => true,
'sort' => 1,
]);

Item::factory()->customUrl('/terms')->create([
'label' => [
'en' => 'Terms of Service',
'sl' => 'Pogoji Uporabe',
],
'menu_id' => $menu->id,
'is_active' => true,
'sort' => 2,
]);

if (Section::count() > 1) {
$section = Section::skip(1)->first();
Item::factory()->linkableToSection()->create([
'label' => [
'en' => 'Latest News',
'sl' => 'Najnovice',
],
'menu_id' => $menu->id,
'linkable_id' => $section->id,
'is_active' => true,
'sort' => 3,
]);
}
}
}
Loading