Complete REST API for an online store with categories, products, and invoicing system.
A fully functional e-commerce API built with Laravel featuring:
- Hierarchical Categories - Unlimited parent/child category relationships
- Product Management - Complete CRUD with inventory tracking
- Invoice System - Automatic price calculation and stock management
- No Authentication - Direct API access (orders via WhatsApp as per requirements)
- β RESTful API architecture
- β Parent/Child category relationships
- β Automatic inventory management
- β Auto-generated invoice numbers
- β Search and filtering
- β Pagination support
- β Comprehensive validation
- β API Resources for clean responses
- β Database seeding with sample data
- β Complete Postman collection
# Install dependencies
composer install
# Run migrations
php artisan migrate
# Seed the database with sample data
php artisan db:seed
# Start the server
php artisan serveThe API will be available at: http://127.0.0.1:8000
- API Documentation - Complete API reference
- Quick Start Guide (Arabic) - Ψ―ΩΩΩ Ψ§ΩΨ¨Ψ―Ψ‘ Ψ§ΩΨ³Ψ±ΩΨΉ Ψ¨Ψ§ΩΨΉΨ±Ψ¨ΩΨ©
- cURL Examples - Ready-to-use cURL commands
- Postman Collection - Import into Postman
- id
- name
- description
- parent_id (nullable, self-referencing)
- timestamps
- id
- name
- description
- price
- amount (inventory)
- unit (piece, kg, liter, etc.)
- category_id
- image (nullable)
- is_active
- timestamps
- id
- invoice_number (auto-generated: INV-YYYYMMDD-0001)
- customer_name
- customer_phone
- customer_address
- total_price (auto-calculated)
- notes
- status (pending, confirmed, completed, cancelled)
- invoice_date
- timestamps
- id
- invoice_id
- product_id
- quantity
- unit_price
- total_price
- timestamps
GET /api/v1/categories - List all categories
GET /api/v1/categories/{id} - Get single category
POST /api/v1/categories - Create category
PUT /api/v1/categories/{id} - Update category
DELETE /api/v1/categories/{id} - Delete category
GET /api/v1/products - List all products
GET /api/v1/products?category_id=1 - Filter by category
GET /api/v1/products?search=phone - Search products
GET /api/v1/products?is_active=1 - Filter active products
GET /api/v1/products/{id} - Get single product
POST /api/v1/products - Create product
PUT /api/v1/products/{id} - Update product
DELETE /api/v1/products/{id} - Delete product
GET /api/v1/invoices - List all invoices
GET /api/v1/invoices?status=pending - Filter by status
GET /api/v1/invoices?date_from=2025-01-01 - Filter by date
GET /api/v1/invoices?search=john - Search invoices
GET /api/v1/invoices/{id} - Get single invoice
POST /api/v1/invoices - Create invoice
PUT /api/v1/invoices/{id} - Update invoice
DELETE /api/v1/invoices/{id} - Delete invoice
After running php artisan db:seed, you'll have:
Categories:
- Electronics (with Phones, Laptops, Accessories)
- Clothing (with Men, Women)
- Food & Beverages (with Snacks, Beverages)
- Home & Garden
Products:
- 12 products across different categories
- Including iPhones, Laptops, Clothing, Food items, etc.
- Open Postman
- Import
postman_collection.json - All endpoints ready to test!
The collection includes:
- β All CRUD operations
- β Search and filtering examples
- β Complete invoice creation workflow
- β Pre-configured base URL
POST /api/v1/invoices
Content-Type: application/json
{
"customer_name": "John Doe",
"customer_phone": "+1234567890",
"customer_address": "123 Main St",
"invoice_date": "2025-12-27",
"items": [
{
"product_id": 1,
"quantity": 2
},
{
"product_id": 5,
"quantity": 1
}
]
}What happens:
- β Invoice number auto-generated (e.g., INV-20251227-0001)
- β Prices calculated from product prices
- β Total price calculated automatically
- β Inventory reduced for each product
- β Stock validation before processing
- Creating invoice: Stock is automatically reduced
- Deleting invoice: Stock is automatically restored
- Validation: Prevents orders exceeding available stock
Categories can have unlimited nested subcategories:
Electronics (parent)
βββ Phones (child)
βββ Laptops (child)
βββ Accessories (child)
Format: INV-YYYYMMDD-XXXX
- Date-based numbering
- Auto-increments daily
- Unique per invoice
Products and invoices support multiple filters:
/api/v1/products?category_id=1&is_active=1&search=phone&per_page=20
- Framework: Laravel 11
- PHP: 8.2+
- Database: SQLite (easily changeable to MySQL/PostgreSQL)
- API: RESTful with JSON responses
As per requirements, this API is designed to work with:
- WhatsApp order forwarding
- No built-in authentication (can be added later)
- Direct API access from frontend/mobile apps
Feel free to fork and contribute! This is an open-source project.
This project is open-sourced software licensed under the MIT license.
Built with β€οΈ using Laravel