<?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('menus', function (Blueprint $table) {
$table->id();
$table->string('name'); // e.g. "Main Header", "Footer Links"
$table->string('location')->unique(); // e.g. header, footer, footer_legal
$table->string('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
});
Schema::create('menu_items', function (Blueprint $table) {
$table->id();
$table->foreignId('menu_id')->constrained()->cascadeOnDelete();
$table->foreignId('parent_id')->nullable()->constrained('menu_items')->cascadeOnDelete();
$table->string('label'); // display text
$table->string('url')->nullable(); // absolute or relative URL
$table->string('type')->default('custom'); // custom | page | category | product
$table->unsignedBigInteger('reference_id')->nullable(); // FK to page/category/product
$table->string('target')->default('_self'); // _self | _blank
$table->string('icon')->nullable(); // heroicon name (optional)
$table->boolean('is_active')->default(true);
$table->unsignedSmallInteger('sort_order')->default(0);
$table->timestamps();
$table->index(['menu_id', 'sort_order']);
$table->index(['menu_id', 'parent_id']);
});
}
public function down(): void
{
Schema::dropIfExists('menu_items');
Schema::dropIfExists('menus');
}
};