Stage 1

Project & Database Setup

Create a new Laravel project and set up the database schema for an e-commerce platform.

Task

In this stage, you'll create a new Laravel project and set up the database schema for an e-commerce platform. You'll need to create migrations for all the required tables.

Required Tables

Users
User account information
  • id
  • name
  • email
  • password
  • address
  • phone
Products
Product information
  • id
  • name
  • description
  • price
  • stock_quantity
  • category_id
Categories
Product categories
  • id
  • name
  • description
  • parent_id
Orders
Customer orders
  • id
  • user_id
  • total_amount
  • status
  • shipping_address
  • payment_method
Order_Items
Items in each order
  • id
  • order_id
  • product_id
  • quantity
  • unit_price
Reviews
Product reviews
  • id
  • product_id
  • user_id
  • rating
  • comment
Wishlists
User wishlists
  • id
  • user_id
  • product_id

Implementation Steps

1. Create a new Laravel project

composer create-project laravel/laravel ecommerce-workshop

2. Configure your database

Update your .env file with your database credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ecommerce_workshop
DB_USERNAME=root
DB_PASSWORD=

3. Create migrations for each table

Run the following commands to create migration files:

php artisan make:migration create_categories_table
php artisan make:migration create_products_table
php artisan make:migration create_orders_table
php artisan make:migration create_order_items_table
php artisan make:migration create_reviews_table
php artisan make:migration create_wishlists_table

4. Implement the migrations

Here's a template for the categories migration. You need to fill in the appropriate code:

database/migrations/xxxx_xx_xx_xxxxxx_create_categories_table.php
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(): void
{
Schema::create('categories', function (Blueprint $table) {
// TODO: Add columns for the categories table
// - id (auto-incremented primary key)
// - name (string)
// - description (nullable text)
// - parent_id (nullable foreign key to categories table)
// - timestamps
// Your code here...
});
}
public function down(): void
{
// TODO: Drop the categories table
// Your code here...
}
};

Now implement the remaining migrations following the same pattern:

  • Products migration: Include columns for id, name, description, price, stock_quantity, category_id (foreign key), and timestamps.
  • Orders migration: Include columns for id, user_id (foreign key), total_amount, status, shipping_address, payment_method, and timestamps.
  • Order_Items migration: Include columns for id, order_id (foreign key), product_id (foreign key), quantity, unit_price, and timestamps.
  • Reviews migration: Include columns for id, product_id (foreign key), user_id (foreign key), rating, comment, and timestamps.
  • Wishlists migration: Include columns for id, user_id (foreign key), product_id (foreign key), and timestamps.

Hint:

Remember to use the appropriate column types for each field. For example, use $table->string('name') for string columns, $table->text('description') for text columns, and$table->foreignId('category_id')->constrained() for foreign keys.

5. Run the migrations

php artisan migrate

Checkpoint 1

Run the following command and share a screenshot of the output on Slack:

php artisan migrate:status

The output should show all your migrations have run successfully.