Okay, cloning a complex e-commerce platform like Homzmart involves designing a database structure that can handle users, products, categories, brands, variants, inventory, orders, payments, shipping, reviews, promotions, and potentially much more (like a marketplace aspect if vendors are involved, though Homzmart appears more curated/retail).
This isn't a single migration but a suite of complex migrations that build interconnected tables with various data types, indexes, foreign keys, and constraints.
Let's break down the core components and build migrations for them.
Products: Base product info, attributes, variations (SKUs).
Media: Images, potentially videos, attached to products, categories, etc.
Inventory: Stock levels for variants.
Pricing & Promotions: Base prices, sale prices, coupons, discounts.
Cart & Wishlist: User-specific saved items.
Orders: Main order details, items, shipping/billing addresses, status history.
Payments & Transactions: Recording payment attempts and successes.
Shipping: Shipping addresses, methods, tracking.
Reviews & Ratings: User feedback on products.
Addresses: Reusable user addresses.
Migration Strategy:
Order Matters: Create tables that are referenced by foreign keys before creating the tables that reference them (e.g., users, categories, brands before products).
Foreign Keys: Use foreignId() with constrained() for clear, readable foreign key definitions. Define onDelete() actions (e.g., cascade, set null).
Indexes: Add indexes to foreign keys automatically via constrained(). Add additional indexes for frequently searched columns (e.g., product names, SKUs, email addresses) or columns used in WHERE or ORDER BY clauses.
Data Types: Use appropriate types (e.g., decimal for money, text for descriptions, json for flexible data like variant attributes).
Soft Deletes: Use softDeletes() for data you might want to retain for historical purposes even after it's conceptually "deleted" (e.g., users, products, orders).
Timestamps: Use timestamps() for created_at and updated_at.
Let's Build the Migrations (Examples for key tables):
Use php artisan make:migration create_users_table etc., for each table.
1. Users and Roles (Basic RBAC)
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_users_table.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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('phone')->nullable()->unique(); // Optional phone number
$table->boolean('is_admin')->default(false); // Simple admin flag, or use roles
// $table->foreignId('role_id')->nullable()->constrained('roles')->onDelete('set null'); // If using a roles table
$table->rememberToken();
$table->timestamps();
$table->softDeletes(); // Soft deletes for users
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_roles_and_permissions_tables.php
// (Simplified - use a package like Spatie Laravel Permission for production)
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('roles', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('guard_name')->default('web');
$table->timestamps();
});
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('guard_name')->default('web');
$table->timestamps();
});
Schema::create('role_user', function (Blueprint $table) {
$table->foreignId('role_id')->constrained('roles')->onDelete('cascade');
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->primary(['role_id', 'user_id']); // Composite primary key
});
Schema::create('permission_role', function (Blueprint $table) {
$table->foreignId('permission_id')->constrained('permissions')->onDelete('cascade');
$table->foreignId('role_id')->constrained('roles')->onDelete('cascade');
$table->primary(['permission_id', 'role_id']); // Composite primary key
});
}
public function down(): void
{
Schema::dropIfExists('permission_role');
Schema::dropIfExists('role_user');
Schema::dropIfExists('permissions');
Schema::dropIfExists('roles');
}
};
2. Catalog: Categories (Nested) and Brands
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_categories_table.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('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->string('image_path')->nullable(); // Or link to a media table
$table->foreignId('parent_id')->nullable()->constrained('categories')->onDelete('set null'); // Self-referencing for nesting
$table->integer('position')->default(0); // For ordering categories
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('parent_id'); // Index the parent_id for tree traversal queries
$table->index('slug'); // Index slug for fast lookups
});
}
public function down(): void
{
Schema::dropIfExists('categories');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_brands_table.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('brands', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->string('logo_path')->nullable(); // Or link to a media table
$table->timestamps();
$table->index('slug'); // Index slug
});
}
public function down(): void
{
Schema::dropIfExists('brands');
}
};
3. Products, Attributes, and Variants
This is where it gets more complex. A common approach is:
product_variants table (specific SKUs, linking to product and attribute values)
Pivot tables to link products to categories (many-to-many if a product can be in multiple), products to attributes (defining which attributes are relevant for a product type), and variants to attribute values (defining the specific combination for a variant).
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_products_table.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('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->string('sku')->unique()->nullable(); // Base SKU, maybe not used if only variants have SKUs
$table->longText('description');
$table->text('short_description')->nullable();
$table->decimal('price', 10, 2); // Base price, could be on variants instead
$table->decimal('sale_price', 10, 2)->nullable();
$table->timestamp('sale_price_expires_at')->nullable();
$table->boolean('manage_stock')->default(true);
$table->integer('stock_quantity')->nullable(); // Stock if not using variants, or global stock
$table->boolean('is_virtual')->default(false);
$table->boolean('is_downloadable')->default(false);
$table->boolean('is_active')->default(true);
$table->unsignedBigInteger('brand_id')->nullable(); // Foreign key to brands
// $table->unsignedBigInteger('category_id')->nullable(); // Primary category, or use pivot for many-to-many
$table->timestamps();
$table->softDeletes(); // Soft deletes for products
// Foreign key constraints - set after creating brands and categories
$table->foreign('brand_id')->references('id')->on('brands')->onDelete('set null');
// $table->foreign('category_id')->references('id')->on('categories')->onDelete('set null');
$table->index('slug'); // Index slug for fast lookups
$table->index('sku'); // Index SKU
$table->index(['price', 'sale_price']); // Indexes for sorting/filtering by price
});
}
public function down(): void
{
Schema::dropIfExists('products');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_product_category_pivot_table.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('product_category', function (Blueprint $table) {
$table->foreignId('product_id')->constrained('products')->onDelete('cascade');
$table->foreignId('category_id')->constrained('categories')->onDelete('cascade');
$table->primary(['product_id', 'category_id']); // Composite primary key
});
}
public function down(): void
{
Schema::dropIfExists('product_category');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_attributes_table.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('attributes', function (Blueprint $table) {
$table->id();
$table->string('name')->unique(); // e.g., 'Color', 'Size', 'Material'
$table->string('slug')->unique();
$table->string('display_type')->nullable(); // e.g., 'color-swatch', 'dropdown', 'text'
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('attributes');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_attribute_values_table.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('attribute_values', function (Blueprint $table) {
$table->id();
$table->foreignId('attribute_id')->constrained('attributes')->onDelete('cascade');
$table->string('value'); // e.g., 'Red', 'Large', 'Wood'
$table->string('slug')->index(); // slug for the value, e.g., 'red', 'large'
$table->string('color_code')->nullable(); // e.g., #FF0000 for color swatches
$table->integer('position')->default(0); // For ordering values
$table->timestamps();
$table->unique(['attribute_id', 'slug']); // Ensure values are unique per attribute
});
}
public function down(): void
{
Schema::dropIfExists('attribute_values');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_product_variants_table.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('product_variants', function (Blueprint $table) {
$table->id();
$table->foreignId('product_id')->constrained('products')->onDelete('cascade');
$table->string('sku')->unique()->nullable();
$table->string('name_modifier')->nullable(); // e.g., " - Red, Large" to append to product name
$table->decimal('price', 10, 2)->nullable(); // Variant specific price (overrides product price)
$table->decimal('sale_price', 10, 2)->nullable();
$table->timestamp('sale_price_expires_at')->nullable();
$table->integer('stock_quantity')->default(0);
$table->string('image_path')->nullable(); // Variant specific image
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->softDeletes(); // Soft delete variants
$table->index('sku'); // Index SKU
$table->index('product_id'); // Index product_id
});
}
public function down(): void
{
Schema::dropIfExists('product_variants');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_attribute_value_product_variant_pivot_table.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
{
// Links which attribute values make up a specific product variant
Schema::create('attribute_value_product_variant', function (Blueprint $table) {
$table->foreignId('attribute_value_id')->constrained('attribute_values')->onDelete('cascade');
$table->foreignId('product_variant_id')->constrained('product_variants')->onDelete('cascade');
$table->primary(['attribute_value_id', 'product_variant_id'], 'attr_val_prod_variant_primary'); // Composite primary key
// You might want to link directly to the attribute here for easier queries
// $table->foreignId('attribute_id')->constrained('attributes')->onDelete('cascade');
// $table->index('attribute_id'); // Index for performance
// $table->unique(['product_variant_id', 'attribute_id']); // A variant should only have one value per attribute type
});
}
public function down(): void
{
Schema::dropIfExists('attribute_value_product_variant');
}
};
4. Media (Polymorphic)
A media table using polymorphic relations is flexible for attaching images to products, categories, brands, users, etc.
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_media_table.php
// (Simplified - use a package like Spatie Laravel Media Library for production)
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('media', function (Blueprint $table) {
$table->id();
$table->morphs('mediable'); // mediable_id and mediable_type
$table->string('collection_name'); // e.g., 'product_images', 'category_banner'
$table->string('file_name'); // Original file name
$table->string('path'); // Storage path (e.g., 'products/1/image.jpg')
$table->string('mime_type')->nullable();
$table->unsignedBigInteger('size'); // File size in bytes
$table->string('disk')->default('public');
$table->string('conversions_disk')->nullable();
$table->json('manipulations')->nullable(); // JSON for image manipulations
$table->json('custom_properties')->nullable(); // JSON for extra data (e.g., alt text)
$table->json('responsive_images')->nullable(); // JSON for responsive image info
$table->integer('order_column')->nullable()->index(); // For ordering media within a collection
$table->timestamps();
$table->index(['mediable_type', 'mediable_id']); // Index for polymorphic lookups
});
}
public function down(): void
{
Schema::dropIfExists('media');
}
};
5. Cart and Wishlist
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_carts_table.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('carts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained('users')->onDelete('cascade'); // Nullable for guest carts
$table->string('session_id')->nullable()->unique(); // For guest carts
$table->timestamps();
$table->unique(['user_id', 'session_id']); // Ensure only one cart per user/session
});
}
public function down(): void
{
Schema::dropIfExists('carts');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_cart_items_table.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('cart_items', function (Blueprint $table) {
$table->id();
$table->foreignId('cart_id')->constrained('carts')->onDelete('cascade');
// Link to variant or product. Variant is better for precise pricing/stock.
$table->foreignId('product_variant_id')->nullable()->constrained('product_variants')->onDelete('cascade');
$table->foreignId('product_id')->nullable()->constrained('products')->onDelete('cascade'); // Fallback or if no variants
$table->integer('quantity')->default(1);
// Store price at time of adding for potential caching/simplicity, but calc on the fly for accuracy
$table->decimal('price_at_addition', 10, 2)->nullable();
$table->timestamps();
$table->unique(['cart_id', 'product_variant_id']); // Ensure unique item per cart
$table->index('cart_id');
$table->index(['product_id', 'product_variant_id']);
});
}
public function down(): void
{
Schema::dropIfExists('cart_items');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_wishlists_table.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('wishlists', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->string('name')->nullable(); // User might have multiple wishlists
$table->timestamps();
$table->unique(['user_id', 'name']); // Ensure unique wishlist name per user
});
}
public function down(): void
{
Schema::dropIfExists('wishlists');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_wishlist_items_table.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('wishlist_items', function (Blueprint $table) {
$table->id();
$table->foreignId('wishlist_id')->constrained('wishlists')->onDelete('cascade');
// Link to variant or product
$table->foreignId('product_variant_id')->nullable()->constrained('product_variants')->onDelete('cascade');
$table->foreignId('product_id')->nullable()->constrained('products')->onDelete('cascade'); // Fallback or if no variants
$table->timestamps();
$table->unique(['wishlist_id', 'product_variant_id']); // Ensure unique item per wishlist
$table->index('wishlist_id');
$table->index(['product_id', 'product_variant_id']);
});
}
public function down(): void
{
Schema::dropIfExists('wishlist_items');
}
};
6. Orders, Payments, Shipping, Addresses
Orders involve capturing the state of the items at the time of purchase, customer info, payment, and shipping.
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_addresses_table.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('addresses', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained('users')->onDelete('cascade'); // Nullable for guest orders
$table->string('type')->nullable(); // e.g., 'shipping', 'billing', 'other'. Useful for user addresses.
$table->string('first_name');
$table->string('last_name');
$table->string('company')->nullable();
$table->string('address_line_1');
$table->string('address_line_2')->nullable();
$table->string('city');
$table->string('state')->nullable(); // Could be state/province/region
$table->string('zip_code')->nullable();
$table->string('country');
$table->string('phone')->nullable();
$table->string('email')->nullable();
$table->timestamps();
$table->index('user_id'); // Index user_id
});
}
public function down(): void
{
Schema::dropIfExists('addresses');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_orders_table.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('orders', function (Blueprint $table) {
$table->id();
$table->string('order_number')->unique(); // Unique order identifier
$table->foreignId('user_id')->nullable()->constrained('users')->onDelete('set null'); // Keep order if user deleted
$table->foreignId('shipping_address_id')->nullable()->constrained('addresses')->onDelete('set null'); // Link to address table
$table->foreignId('billing_address_id')->nullable()->constrained('addresses')->onDelete('set null'); // Link to address table
// $table->foreignId('payment_method_id')->nullable()->constrained('payment_methods')->onDelete('set null'); // If using payment methods table
// $table->foreignId('shipping_method_id')->nullable()->constrained('shipping_methods')->onDelete('set null'); // If using shipping methods table
$table->decimal('subtotal', 10, 2);
$table->decimal('shipping_cost', 10, 2)->default(0);
$table->decimal('discount_amount', 10, 2)->default(0); // Total discount applied
$table->decimal('tax_amount', 10, 2)->default(0);
$table->decimal('total', 10, 2);
$table->string('currency')->default('USD');
$table->string('status')->default('pending'); // e.g., pending, processing, shipped, delivered, cancelled, failed
$table->text('notes')->nullable();
$table->timestamps();
$table->softDeletes(); // Soft deletes for orders
$table->index('user_id');
$table->index('order_number');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('orders');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_order_items_table.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('order_items', function (Blueprint $table) {
$table->id();
$table->foreignId('order_id')->constrained('orders')->onDelete('cascade');
// Link to original product/variant, but also snapshot data
$table->foreignId('product_variant_id')->nullable()->constrained('product_variants')->onDelete('set null');
$table->foreignId('product_id')->nullable()->constrained('products')->onDelete('set null'); // Fallback
// Snapshot of product/variant details at the time of order
$table->string('name');
$table->string('sku')->nullable();
$table->decimal('unit_price', 10, 2); // Price per item
$table->integer('quantity');
$table->decimal('subtotal', 10, 2); // unit_price * quantity
$table->decimal('total', 10, 2); // subtotal - item_discount + item_tax (if item-level)
$table->string('image_path')->nullable(); // Snapshot of the image
// Snapshot of variant attributes (optional, can store as JSON)
$table->json('variant_attributes')->nullable(); // e.g., [{'name': 'Color', 'value': 'Red'}, {'name': 'Size', 'value': 'Large'}]
$table->timestamps();
$table->index('order_id');
$table->index(['product_id', 'product_variant_id']);
});
}
public function down(): void
{
Schema::dropIfExists('order_items');
}
};
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_payments_table.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('payments', function (Blueprint $table) {
$table->id();
$table->foreignId('order_id')->constrained('orders')->onDelete('cascade'); // Link payment to order
$table->string('payment_gateway'); // e.g., 'stripe', 'paypal', 'payfort'
$table->string('gateway_transaction_id')->nullable(); // ID from the payment gateway
$table->string('method')->nullable(); // e.g., 'card', 'transfer', 'cash_on_delivery'
$table->decimal('amount', 10, 2);
$table->string('currency')->default('USD');
$table->string('status')->default('pending'); // e.g., 'pending', 'completed', 'failed', 'refunded'
$table->json('details')->nullable(); // Store gateway response/details as JSON
$table->timestamps();
$table->index('order_id');
$table->index('gateway_transaction_id');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('payments');
}
};
7. Reviews
php
// database/migrations/xxxx_xx_xx_xxxxxx_create_reviews_table.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('reviews', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained('users')->onDelete('set null'); // Allow reviews from guests? (less common) or keep review if user deleted
$table->foreignId('product_id')->constrained('products')->onDelete('cascade');
$table->foreignId('order_item_id')->nullable()->constrained('order_items')->onDelete('set null'); // Optional: Link to purchased item to verify review legitimacy
$table->integer('rating')->unsigned(); // e.g., 1 to 5
$table->text('comment')->nullable();
$table->string('status')->default('pending'); // e.g., pending, approved, rejected
$table->timestamp('approved_at')->nullable();
$table->timestamps();
$table->softDeletes(); // Soft delete reviews
$table->unique(['user_id', 'product_id']); // Prevent multiple reviews per user per product (adjust if needed)
$table->index('product_id');
$table->index('user_id');
$table->index('rating');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('reviews');
}
};
Additional Complexities & Tables (Consider as needed):
Coupons/Discounts: Tables for coupon codes, discount rules (percentage, fixed amount, buy X get Y), rules for applicability (products, categories, users), usage tracking.
Shipping Methods/Zones: Tables defining available shipping options, costs, and geographical zones.
Payment Methods: Table listing available payment options (Cash on Delivery, Credit Card, etc.).
Taxes: Tables for tax rules, rates, and zones.
Store Settings: A key-value store table for site-wide configuration.
Audit Logs: Tables to track changes made to sensitive data (orders, products, users).
Notifications: Tables for user notifications.
CMS Pages: Tables for static content (About Us, Contact, Terms).
Marketplace Specific: If vendors/sellers are involved, tables for vendor details, vendor payout information, vendor-specific products/inventory/orders/reviews.
Putting it all together (Conceptual Migration Order):
create_order_items_table (Depends on orders, products, product_variants)
create_reviews_table (Depends on users, products, order_items)
... and so on for other features like coupons, shipping, etc.
Important Considerations:
Performance: For very large tables (products, orders), ensure proper indexing. Consider database-level full-text search if required for product descriptions.
Scalability: This structure is a good starting point, but extreme scale might require database sharding or other advanced techniques later.
Data Integrity: Foreign key constraints are crucial. onDelete('cascade') is powerful but use with caution. set null is safer if you need to keep the referencing record.
Flexibility: The attribute/variant structure provides flexibility for different product types. The polymorphic media table allows easy attachment of images to various models.
Evolution: Migrations are designed for change. Plan to add new migrations as features are added or requirements change. Schema::table is used for altering existing tables.
This provides a solid foundation for a complex e-commerce database structure in Laravel migrations, mimicking the complexity you'd find in a platform like Homzmart. Remember to adjust column names, data types, and relationships based on your specific feature requirements.