A Laravel-based e-commerce management system that allows administrators to manage products and orders, and users to search products, place orders, make payments, and handle order updates.
The system follows modern clean architecture principles: Thin Controllers, Fat Models, Service Layer for complex logic, Form Requests for validation, Resources for API responses, Traits for reusable logic, and Custom Exceptions for consistent error handling.
- Add, update, delete, and list products.
- Update order status.
- Search products by name.
- Create and manage orders.
- Process payments.
- View, cancel, or update orders.
- Update product quantity in orders.
- Remove products from orders.
- Register & login with role-based tokens (admin/user).
- Logout.
- Standardized API responses via
Resources
andApiResponse
Trait. - Validation via
Form Requests
with custom JSON error responses. - Business exceptions with unified JSON responses.
- Database relationships: Products, Orders, OrderProducts, Categories, Users with roles.
- PHP >= 8.1
- Laravel >= 10.x
- Composer
- MySQL (or any supported DB)
- Laravel Sanctum (API authentication)
- Spatie Laravel Permission (roles/permissions)
- Storage for product images (public disk)
app/
├── Exceptions/ # Custom business exceptions
│ ├── BaseBusinessException.php
│ ├── QuantityExceededException.php
│ ├── OrderAlreadyPaidException.php
│ ├── InvalidPaymentAmountException.php
│ └── AuthenticationFailedException.php
│
├── Http/
│ ├── Controllers/ # Thin controllers
│ │ ├── Admin/
│ │ ├── Auth/
│ │ └── User/
│ │
│ ├── Requests/ # Validation requests
│ ├── Resources/ # API resources
│ └── Traits/ # Reusable traits
│
├── Models/ # Fat models with business logic
│
├── Repository/ # Query repositories with BaseFilter
│
└── Services/ # Services for complex operations
## Key Components
- **Models (Fat Models):** contain business logic, relationships, stock/payment checks.
- **Controllers (Thin):** delegate to services/models, return Resources.
- **Services:** encapsulate complex logic (transactions, multi-model ops).
- **Form Requests:** validation with standardized JSON error replies.
- **Resources:** unified API output format.
- **Traits:** reusable `ApiResponse` & `ApiValidationResponse`.
- **Exceptions:** domain-specific (e.g., `QuantityExceededException`).
- **Repositories:** extend `BaseFilter` to support dynamic filtering, search, sort, price range, relationships.
## Error Handling
- **Validation errors:** handled by Form Requests with JSON 400.
- **Business errors:** handled via custom Exceptions with JSON responses.
- **Global handler:** catches unhandled exceptions and formats JSON output