A Laravel mini e-commerce project designed for students. It covers fundamental concepts like product display, cart management using sessions, user authentication with Breeze, a simulated checkout process, and a contact form that saves messages to the database.
License: MIT
- Home Page: Displays a grid of products with images and prices. (Day 2)
- Product Detail: View a single product at
/product/{id}. (Day 3) - Shopping Cart (Session-based): Add, update, remove items, and clear the cart. (Day 3)
- Authentication: User registration, login, and logout powered by Laravel Breeze (Blade). (Day 4)
- Checkout: A simple, auth-protected checkout process that shows an order summary and a success page, then clears the cart. (Day 4)
- Contact Form: A contact page with a form that saves messages directly to the
contact_messagestable and shows a success flash message. (Day 5) - Basic UI: A clean navigation bar and layout using Bootstrap 5 (CDN).
- Backend: Laravel 11, PHP 8.2+
- Database: MySQL / MariaDB
- Frontend: Blade, Vite, Bootstrap 5 (CDN)
- Dev Tools: Node.js 20+
-
Clone the repository:
git clone https://github.com/your-username/blushop-laravel.git cd blushop-laravel -
Install PHP dependencies:
composer install
-
Set up your environment:
- Copy the example environment file:
cp .env.example .env
- Generate the application key:
php artisan key:generate
- Copy the example environment file:
-
Configure the database:
- Create a new database in MySQL/MariaDB (e.g.,
blushop_db). - Update the
.envfile with your database credentials:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=blushop_db DB_USERNAME=root DB_PASSWORD=your_password_here (mine is root)
- Create a new database in MySQL/MariaDB (e.g.,
-
Run database migrations:
php artisan migrate
-
(Optional) Seed demo products:
php artisan db:seed --class=Database\Seeders\ProductSeeder
-
Install frontend dependencies (for Breeze):
npm install
-
Run the development servers:
- Start the Vite development server:
npm run dev
- In a new terminal, start the PHP development server:
php artisan serve
- Start the Vite development server:
The application will be available at http://127.0.0.1:8002.
-
productsid(PK)name(string)description(text, nullable)price(decimal 8,2)image(string) - Stores path to image file inpublic/imagescreated_at,updated_at
-
contact_messagesid(PK)name(string)email(string)message(text)created_at
-
users(Managed by Laravel Breeze)id,name,email,password, etc.
| Method | Path | Controller@Action | Middleware | Description |
|---|---|---|---|---|
GET |
/ |
ProductController@index |
web |
Show product list (Home) |
GET |
/product/{id} |
ProductController@show |
web |
Show single product detail |
GET |
/cart |
CartController@index |
web |
Show cart page |
POST |
/cart/add/{id} |
CartController@add |
web |
Add product to cart |
POST |
/cart/update/{id} |
CartController@update |
web |
Update product quantity in cart |
POST |
/cart/remove/{id} |
CartController@remove |
web |
Remove product from cart |
POST |
/cart/clear |
CartController@clear |
web |
Clear all items from cart |
GET |
/checkout |
CheckoutController@index |
auth |
Show checkout summary page |
POST |
/checkout/place |
CheckoutController@place |
auth |
"Place" the order |
GET |
/contact |
ContactController@index |
web |
Show contact form |
POST |
/contact |
ContactController@send |
web |
Submit contact message |
GET |
/login, /register |
(Breeze) | guest |
Auth pages |
POST |
/logout |
(Breeze) | auth |
Logout user |
- Input Validation: All incoming requests are validated (e.g., cart quantity must be >= 1, contact fields have min length).
- Secure:
findOrFailis used to prevent errors on missing products. CSRF protection is enabled on all forms. Server-side calculations are used for cart totals. - Good UX: Flash messages provide feedback. The cart badge updates with the item count.
- Demo Images: Product images are located in
public/images.
While the current MVP (Minimum Viable Product) meets all functional requirements, the following technical improvements are planned to scale the application for production:
-
Caching Strategy: Implement Redis to handle session management and cache heavy database queries (e.g., product lists) for faster load times.
-
Asynchronous Processing: Utilize Laravel Queues (via Redis/Horizon) to handle email sending (Contact Form) in the background, preventing UI blocking.
-
API Development: Expose RESTful API endpoints with Sanctum authentication to support a potential mobile app (Flutter/React Native) in the future.
-
Payment Gateway: Replace the simulated checkout with real-world integration using Stripe or VNPay (Sandbox mode) handling Webhooks for order status updates.
-
Filesystem Abstraction: Migrate image storage from local disk (
public/) to cloud storage (AWS S3 or MinIO) to support stateless deployment.
-
Containerization: Fully Dockerize the application using Docker Compose (Nginx, PHP, MySQL, Redis) to ensure environment consistency.
-
Automated Testing: Increase test coverage using Pest PHP for Feature and Unit tests to prevent regressions during refactoring.
-
CI/CD Pipeline: Set up GitHub Actions to automatically run tests (
php artisan test) and linting (Laravel Pint) on every push.