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.
Notice: it's not an entire Laravel E-Commerce project. It's JUST the database layer.
This is the DB schema:
With factories and seeders, you can play around with various scenarios, here are examples of a few DB tables after php artisan migrate --seed
:
Follow these steps to set up the project locally:
-
Clone the repository:
git clone https://github.com/LaravelDaily/Laravel-Multi-Vendor-E-Commerce-Structure.git project cd project
-
Install dependencies:
composer install
-
Copy the
.env
file and configure your environment variables:cp .env.example .env
-
Generate the application key:
php artisan key:generate
-
Set up the database:
- Update
.env
with your database credentials. - Run migrations and seed the database, repo includes fake tasks:
php artisan migrate --seed
- Update
With this example, we wanted to show you how to structure a bigger application. In this case - an E-Commerce project.
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.
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