This repository is an example of a complex Laravel database with migrations/models/factories/seeders.
The purpose is for developers to take this example and simulate various e-commerce scenarios, evaluate decisions about DB table relationships, and experiment with various Eloquent/SQL queries.
You can find Database Seeders inside the repository, which will generate fake data for you:
database/seeders/DatabaseSeeder.php
class DatabaseSeeder extends Seeder{ /** * Seed the application's database. */ public function run(): void { $this->call([ RoleSeeder::class, PermissionSeeder::class, RolePermissionSeeder::class, OrderStatusSeeder::class, OrderRefundStatusSeeder::class, OrderReturnStatusSeeder::class, OrderShipmentStatusSeeder::class, PaymentMethodSeeder::class, ProductStatusSeeder::class, EmailCampaignStatusSeeder::class, UserSeeder::class, UserAddressSeeder::class, VendorSeeder::class, ProductCategorySeeder::class, ProductAttributeSeeder::class, ProductSeeder::class, ProductReviewSeeder::class, OrderSeeder::class, PaymentVendorSeeder::class, VendorSettingsSeeder::class, VendorPaymentsSeeder::class, VendorReviewsSeeder::class, CouponSeeder::class, ReviewSeeder::class, WishlistSeeder::class, CartSeeder::class, CartItemSeeder::class, EmailCampaignSeeder::class, PromotionSeeder::class, ]); }}
From here, you can play around with the data and see how to write specific queries to get the data you need or generate reports.
DB Structure Decisions to Pay Attention To
We think these points below are interesting to analyze and learn from or experiment with alternatives.
- Each of the User can have multiple addresses, and they are stored in separate table.
- Products can have multiple variations, and they are stored in separate table.
- We are using
decimal
for our prices, as it's more precise thanfloat
. - Order actions (like shipments, returns and refunds) are stored in separate tables.
- Tracking Vendor commissions and payments is a separate table.
- Usage of
restrict
on delete for some tables, likeproducts
andorder_items
. This means that if you have orders, you can't delete products. - Eloquent Casting usage for
datetime
fields