Database Design

Real-world database schemas, ERD concepts, and migration examples.

A many-to-many relationship between users and roles, allowing flexible permission management where users can have multiple roles.

3 tables

A hierarchical category system with products belonging to categories. Categories support nested subcategories via self-referencing parent_id.

2 tables

An e-commerce order system where orders contain multiple line items. Each order belongs to a user and has a status.

2 tables

A classic blog system with posts belonging to users and comments on posts. Comments support nested replies via parent_id.

2 tables

A flexible tagging system using a many-to-many pivot table. Posts and snippets can both be tagged with the same tags.

3 tables

A real-time chat system with conversations, participants, and messages. Supports group conversations and message read status.

3 tables

A learning management system structure with courses containing ordered lessons and tracking user enrollment and progress.

4 tables

An employee attendance tracking system with daily check-in/check-out records, work hours calculation, and shift management.

3 tables

A warehouse inventory management system tracking products, stock levels, movements between warehouses, and stock adjustments.

3 tables

A polymorphic file upload system where any model can have attached files. Uses Laravel morphs for the polymorphic relationship.

1 table

A polymorphic activity logging system that tracks user actions across the application. Used for audit trails and activity feeds.

1 table

A threaded comment system where comments can have unlimited nesting depth via parent_id self-referencing foreign key.

1 table

A polymorphic like/unlike system where users can like any content type (posts, comments, photos). Prevents duplicate likes with a unique constraint.

1 table

A social follow/unfollow system where users can follow other users. Supports follower/following counts and activity feeds.

1 table

A key-value settings table for storing application configuration that can be modified at runtime without code changes.

1 table