hey, help me create a mysql database for an organisation, they will have services and products they sell online, services to be booked like lessons.... they will be posting about their events, news announcements, classes, ... they will have teachers, students, ....
dont hold back think of everything this database will need but dont complicate it like using roles and permissions ....,
make the sql and but also laravel migration schemas
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
I'll help you create a comprehensive database schema for your organization. Here's a complete MySQL database design with both raw SQL and Laravel migrations.
MySQL Database Schema
sql
-- Create database
CREATE DATABASE IF NOT EXISTS organization_db;
USE organization_db;
-- Users table (teachers, students, admins)
CREATE TABLE users (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
email_verified_at TIMESTAMP NULL,
password VARCHAR(255) NOT NULL,
user_type ENUM('admin', 'teacher', 'student', 'customer') DEFAULT 'customer',
phone VARCHAR(20),
address TEXT,
city VARCHAR(100),
state VARCHAR(100),
zip_code VARCHAR(20),
country VARCHAR(100),
bio TEXT,
profile_image VARCHAR(255),
status ENUM('active', 'inactive', 'suspended') DEFAULT 'active',
remember_token VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_user_type (user_type),
INDEX idx_status (status)
);
-- Categories table (for products and services)
CREATE TABLE categories (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
description TEXT,
parent_id BIGINT UNSIGNED NULL,
type ENUM('product', 'service', 'both') DEFAULT 'both',
image VARCHAR(255),
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (parent_id) REFERENCES categories(id) ON DELETE SET NULL,
INDEX idx_slug (slug),
INDEX idx_parent (parent_id)
);
-- Products table
CREATE TABLE products (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
category_id BIGINT UNSIGNED,
name VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
description TEXT,
short_description TEXT,
price DECIMAL(10, 2) NOT NULL,
sale_price DECIMAL(10, 2),
sku VARCHAR(100) UNIQUE,
stock_quantity INT DEFAULT 0,
is_digital BOOLEAN DEFAULT FALSE,
is_featured BOOLEAN DEFAULT FALSE,
is_active BOOLEAN DEFAULT TRUE,
weight DECIMAL(8, 2),
dimensions VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
INDEX idx_slug (slug),
INDEX idx_sku (sku),
INDEX idx_category (category_id)
);
-- Services table
CREATE TABLE services (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
category_id BIGINT UNSIGNED,
teacher_id BIGINT UNSIGNED,
name VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
description TEXT,
duration_minutes INT NOT NULL,
price DECIMAL(10, 2) NOT NULL,
max_participants INT DEFAULT 1,
location VARCHAR(255),
is_online BOOLEAN DEFAULT FALSE,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE SET NULL,
INDEX idx_slug (slug),
INDEX idx_teacher (teacher_id)
);
-- Classes table (recurring services)
CREATE TABLE classes (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
service_id BIGINT UNSIGNED,
teacher_id BIGINT UNSIGNED,
name VARCHAR(255) NOT NULL,
description TEXT,
start_date DATE NOT NULL,
end_date DATE,
schedule JSON, -- Store weekly schedule
max_students INT DEFAULT 20,
enrolled_count INT DEFAULT 0,
price DECIMAL(10, 2) NOT NULL,
location VARCHAR(255),
is_online BOOLEAN DEFAULT FALSE,
status ENUM('upcoming', 'ongoing', 'completed', 'cancelled') DEFAULT 'upcoming',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE SET NULL,
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE SET NULL,
INDEX idx_status (status),
INDEX idx_dates (start_date, end_date)
);
-- Class enrollments
CREATE TABLE class_enrollments (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
class_id BIGINT UNSIGNED NOT NULL,
student_id BIGINT UNSIGNED NOT NULL,
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status ENUM('active', 'completed', 'dropped', 'waitlisted') DEFAULT 'active',
payment_status ENUM('pending', 'paid', 'refunded') DEFAULT 'pending',
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE,
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY unique_enrollment (class_id, student_id),
INDEX idx_student (student_id),
INDEX idx_status (status)
);
-- Bookings table (for individual services/lessons)
CREATE TABLE bookings (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
service_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
teacher_id BIGINT UNSIGNED,
booking_date DATE NOT NULL,
start_time TIME NOT NULL,
end_time TIME NOT NULL,
status ENUM('pending', 'confirmed', 'completed', 'cancelled', 'no_show') DEFAULT 'pending',
payment_status ENUM('pending', 'paid', 'refunded') DEFAULT 'pending',
total_amount DECIMAL(10, 2) NOT NULL,
notes TEXT,
cancellation_reason TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE SET NULL,
INDEX idx_date (booking_date),
INDEX idx_user (user_id),
INDEX idx_teacher (teacher_id),
INDEX idx_status (status)
);
-- Events table
CREATE TABLE events (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
description TEXT,
start_datetime DATETIME NOT NULL,
end_datetime DATETIME NOT NULL,
location VARCHAR(255),
is_online BOOLEAN DEFAULT FALSE,
max_attendees INT,
current_attendees INT DEFAULT 0,
price DECIMAL(10, 2) DEFAULT 0,
image VARCHAR(255),
status ENUM('draft', 'published', 'cancelled') DEFAULT 'draft',
created_by BIGINT UNSIGNED,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
INDEX idx_slug (slug),
INDEX idx_datetime (start_datetime, end_datetime),
INDEX idx_status (status)
);
-- Event registrations
CREATE TABLE event_registrations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
event_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status ENUM('registered', 'attended', 'cancelled', 'no_show') DEFAULT 'registered',
payment_status ENUM('pending', 'paid', 'refunded') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY unique_registration (event_id, user_id)
);
-- News/Announcements table
CREATE TABLE announcements (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
content TEXT NOT NULL,
excerpt TEXT,
type ENUM('news', 'announcement', 'update') DEFAULT 'news',
priority ENUM('low', 'normal', 'high', 'urgent') DEFAULT 'normal',
image VARCHAR(255),
is_published BOOLEAN DEFAULT FALSE,
published_at TIMESTAMP NULL,
author_id BIGINT UNSIGNED,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL,
INDEX idx_slug (slug),
INDEX idx_published (is_published, published_at),
INDEX idx_type (type)
);
-- Orders table
CREATE TABLE orders (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,
order_number VARCHAR(50) UNIQUE NOT NULL,
subtotal DECIMAL(10, 2) NOT NULL,
tax_amount DECIMAL(10, 2) DEFAULT 0,
shipping_amount DECIMAL(10, 2) DEFAULT 0,
discount_amount DECIMAL(10, 2) DEFAULT 0,
total_amount DECIMAL(10, 2) NOT NULL,
status ENUM('pending', 'processing', 'completed', 'cancelled', 'refunded') DEFAULT 'pending',
payment_method VARCHAR(50),
payment_status ENUM('pending', 'paid', 'failed', 'refunded') DEFAULT 'pending',
shipping_address TEXT,
billing_address TEXT,
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
INDEX idx_order_number (order_number),
INDEX idx_user (user_id),
INDEX idx_status (status),
INDEX idx_created (created_at)
);
-- Order items table
CREATE TABLE order_items (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_id BIGINT UNSIGNED NOT NULL,
item_type ENUM('product', 'service', 'booking', 'event', 'class') NOT NULL,
item_id BIGINT UNSIGNED NOT NULL,
quantity INT NOT NULL DEFAULT 1,
price DECIMAL(10, 2) NOT NULL,
total DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE,
INDEX idx_order (order_id),
INDEX idx_item (item_type, item_id)
);
-- Media/Images table
CREATE TABLE media (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
mediable_type VARCHAR(255) NOT NULL,
mediable_id BIGINT UNSIGNED NOT NULL,
type ENUM('image', 'video', 'document') DEFAULT 'image',
file_path VARCHAR(255) NOT NULL,
file_name VARCHAR(255) NOT NULL,
mime_type VARCHAR(100),
file_size INT,
is_primary BOOLEAN DEFAULT FALSE,
sort_order INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_mediable (mediable_type, mediable_id),
INDEX idx_primary (is_primary)
);
-- Reviews table
CREATE TABLE reviews (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
reviewable_type VARCHAR(255) NOT NULL,
reviewable_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
rating INT NOT NULL CHECK (rating >= 1 AND rating <= 5),
title VARCHAR(255),
comment TEXT,
is_verified BOOLEAN DEFAULT FALSE,
is_published BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
INDEX idx_reviewable (reviewable_type, reviewable_id),
INDEX idx_user (user_id),
INDEX idx_rating (rating)
);
-- Teacher availability
CREATE TABLE teacher_availability (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
teacher_id BIGINT UNSIGNED NOT NULL,
day_of_week TINYINT NOT NULL CHECK (day_of_week >= 0 AND day_of_week <= 6),
start_time TIME NOT NULL,
end_time TIME NOT NULL,
is_available BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE CASCADE,
INDEX idx_teacher (teacher_id),
INDEX idx_day (day_of_week)
);
Laravel Migration Files
1. Users Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
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->enum('user_type', ['admin', 'teacher', 'student', 'customer'])->default('customer');
$table->string('phone', 20)->nullable();
$table->text('address')->nullable();
$table->string('city', 100)->nullable();
$table->string('state', 100)->nullable();
$table->string('zip_code', 20)->nullable();
$table->string('country', 100)->nullable();
$table->text('bio')->nullable();
$table->string('profile_image')->nullable();
$table->enum('status', ['active', 'inactive', 'suspended'])->default('active');
$table->rememberToken();
$table->timestamps();
$table->index('user_type');
$table->index('status');
});
}
public function down()
{
Schema::dropIfExists('users');
}
};
2. Categories Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->foreignId('parent_id')->nullable()->constrained('categories')->onDelete('set null');
$table->enum('type', ['product', 'service', 'both'])->default('both');
$table->string('image')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('slug');
$table->index('parent_id');
});
}
public function down()
{
Schema::dropIfExists('categories');
}
};
3. Products Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->onDelete('set null');
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->text('short_description')->nullable();
$table->decimal('price', 10, 2);
$table->decimal('sale_price', 10, 2)->nullable();
$table->string('sku', 100)->unique()->nullable();
$table->integer('stock_quantity')->default(0);
$table->boolean('is_digital')->default(false);
$table->boolean('is_featured')->default(false);
$table->boolean('is_active')->default(true);
$table->decimal('weight', 8, 2)->nullable();
$table->string('dimensions', 100)->nullable();
$table->timestamps();
$table->index('slug');
$table->index('sku');
$table->index('category_id');
});
}
public function down()
{
Schema::dropIfExists('products');
}
};
4. Services Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('services', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->nullable()->constrained()->onDelete('set null');
$table->foreignId('teacher_id')->nullable()->constrained('users')->onDelete('set null');
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->integer('duration_minutes');
$table->decimal('price', 10, 2);
$table->integer('max_participants')->default(1);
$table->string('location')->nullable();
$table->boolean('is_online')->default(false);
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('slug');
$table->index('teacher_id');
});
}
public function down()
{
Schema::dropIfExists('services');
}
};
5. Classes Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('classes', function (Blueprint $table) {
$table->id();
$table->foreignId('service_id')->nullable()->constrained()->onDelete('set null');
$table->foreignId('teacher_id')->nullable()->constrained('users')->onDelete('set null');
$table->string('name');
$table->text('description')->nullable();
$table->date('start_date');
$table->date('end_date')->nullable();
$table->json('schedule')->nullable();
$table->integer('max_students')->default(20);
$table->integer('enrolled_count')->default(0);
$table->decimal('price', 10, 2);
$table->string('location')->nullable();
$table->boolean('is_online')->default(false);
$table->enum('status', ['upcoming', 'ongoing', 'completed', 'cancelled'])->default('upcoming');
$table->timestamps();
$table->index('status');
$table->index(['start_date', 'end_date']);
});
}
public function down()
{
Schema::dropIfExists('classes');
}
};
6. Class Enrollments Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('class_enrollments', function (Blueprint $table) {
$table->id();
$table->foreignId('class_id')->constrained()->onDelete('cascade');
$table->foreignId('student_id')->constrained('users')->onDelete('cascade');
$table->timestamp('enrollment_date')->useCurrent();
$table->enum('status', ['active', 'completed', 'dropped', 'waitlisted'])->default('active');
$table->enum('payment_status', ['pending', 'paid', 'refunded'])->default('pending');
$table->text('notes')->nullable();
$table->timestamps();
$table->unique(['class_id', 'student_id']);
$table->index('student_id');
$table->index('status');
});
}
public function down()
{
Schema::dropIfExists('class_enrollments');
}
};
7. Bookings Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->id();
$table->foreignId('service_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('teacher_id')->nullable()->constrained('users')->onDelete('set null');
$table->date('booking_date');
$table->time('start_time');
$table->time('end_time');
$table->enum('status', ['pending', 'confirmed', 'completed', 'cancelled', 'no_show'])->default('pending');
$table->enum('payment_status', ['pending', 'paid', 'refunded'])->default('pending');
$table->decimal('total_amount', 10, 2);
$table->text('notes')->nullable();
$table->text('cancellation_reason')->nullable();
$table->timestamps();
$table->index('booking_date');
$table->index('user_id');
$table->index('teacher_id');
$table->index('status');
});
}
public function down()
{
Schema::dropIfExists('bookings');
}
};
8. Events Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('events', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->dateTime('start_datetime');
$table->dateTime('end_datetime');
$table->string('location')->nullable();
$table->boolean('is_online')->default(false);
$table->integer('max_attendees')->nullable();
$table->integer('current_attendees')->default(0);
$table->decimal('price', 10, 2)->default(0);
$table->string('image')->nullable();
$table->enum('status', ['draft', 'published', 'cancelled'])->default('draft');
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
$table->timestamps();
$table->index('slug');
$table->index(['start_datetime', 'end_datetime']);
$table->index('status');
});
}
public function down()
{
Schema::dropIfExists('events');
}
};
9. Event Registrations Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('event_registrations', function (Blueprint $table) {
$table->id();
$table->foreignId('event_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->timestamp('registration_date')->useCurrent();
$table->enum('status', ['registered', 'attended', 'cancelled', 'no_show'])->default('registered');
$table->enum('payment_status', ['pending', 'paid', 'refunded'])->default('pending');
$table->timestamps();
$table->unique(['event_id', 'user_id']);
});
}
public function down()
{
Schema::dropIfExists('event_registrations');
}
};
10. Announcements Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('announcements', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->text('content');
$table->text('excerpt')->nullable();
$table->enum('type', ['news', 'announcement', 'update'])->default('news');
$table->enum('priority', ['low', 'normal', 'high', 'urgent'])->default('normal');
$table->string('image')->nullable();
$table->boolean('is_published')->default(false);
$table->timestamp('published_at')->nullable();
$table->foreignId('author_id')->nullable()->constrained('users')->onDelete('set null');
$table->timestamps();
$table->index('slug');
$table->index(['is_published', 'published_at']);
$table->index('type');
});
}
public function down()
{
Schema::dropIfExists('announcements');
}
};
11. Orders Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('order_number', 50)->unique();
$table->decimal('subtotal', 10, 2);
$table->decimal('tax_amount', 10, 2)->default(0);
$table->decimal('shipping_amount', 10, 2)->default(0);
$table->decimal('discount_amount', 10, 2)->default(0);
$table->decimal('total_amount', 10, 2);
$table->enum('status', ['pending', 'processing', 'completed', 'cancelled', 'refunded'])->default('pending');
$table->string('payment_method', 50)->nullable();
$table->enum('payment_status', ['pending', 'paid', 'failed', 'refunded'])->default('pending');
$table->text('shipping_address')->nullable();
$table->text('billing_address')->nullable();
$table->text('notes')->nullable();
$table->timestamps();
$table->index('order_number');
$table->index('user_id');
$table->index('status');
$table->index('created_at');
});
}
public function down()
{
Schema::dropIfExists('orders');
}
};
12. Order Items Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('order_items', function (Blueprint $table) {
$table->id();
$table->foreignId('order_id')->constrained()->onDelete('cascade');
$table->enum('item_type', ['product', 'service', 'booking', 'event', 'class']);
$table->unsignedBigInteger('item_id');
$table->integer('quantity')->default(1);
$table->decimal('price', 10, 2);
$table->decimal('total', 10, 2);
$table->timestamps();
$table->index('order_id');
$table->index(['item_type', 'item_id']);
});
}
public function down()
{
Schema::dropIfExists('order_items');
}
};
13. Media Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('media', function (Blueprint $table) {
$table->id();
$table->string('mediable_type');
$table->unsignedBigInteger('mediable_id');
$table->enum('type', ['image', 'video', 'document'])->default('image');
$table->string('file_path');
$table->string('file_name');
$table->string('mime_type', 100)->nullable();
$table->integer('file_size')->nullable();
$table->boolean('is_primary')->default(false);
$table->integer('sort_order')->default(0);
$table->timestamps();
$table->index(['mediable_type', 'mediable_id']);
$table->index('is_primary');
});
}
public function down()
{
Schema::dropIfExists('media');
}
};
14. Reviews Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('reviews', function (Blueprint $table) {
$table->id();
$table->string('reviewable_type');
$table->unsignedBigInteger('reviewable_id');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->integer('rating');
$table->string('title')->nullable();
$table->text('comment')->nullable();
$table->boolean('is_verified')->default(false);
$table->boolean('is_published')->default(true);
$table->timestamps();
$table->index(['reviewable_type', 'reviewable_id']);
$table->index('user_id');
$table->index('rating');
});
}
public function down()
{
Schema::dropIfExists('reviews');
}
};
15. Teacher Availability Migration
php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('teacher_availability', function (Blueprint $table) {
$table->id();
$table->foreignId('teacher_id')->constrained('users')->onDelete('cascade');
$table->tinyInteger('day_of_week'); // 0 = Sunday, 6 = Saturday
$table->time('start_time');
$table->time('end_time');
$table->boolean('is_available')->default(true);
$table->timestamps();
$table->index('teacher_id');
$table->index('day_of_week');
});
}
public function down()
{
Schema::dropIfExists('teacher_availability');
}
};
This comprehensive database schema covers all the requirements you mentioned:
Products & Services: Complete e-commerce functionality with categories, inventory tracking, and pricing
Bookings & Classes: Flexible booking system for individual lessons and recurring classes
Events & Announcements: Full content management for news, events, and updates
Users: Simple user type system (admin, teacher, student, customer) without complex roles
Orders & Payments: Complete order management with flexible item types
Media & Reviews: Support for images, files, and customer reviews
Teacher Management: Availability scheduling and assignment to services/classes
The schema uses polymorphic relationships for media and reviews, allowing them to be attached to multiple entity types. It includes proper indexing for performance and maintains referential integrity with foreign key constraints.