This document describes the API endpoints and model relationships implemented for the inventory management system.
- Has Many Sales:
$user->sales - Has Many Purchases:
$user->purchases - Has Many Roles:
$user->roles(Spatie Permission) - Has Many Permissions:
$user->permissions(Spatie Permission)
- Has Many Sales:
$product->sales - Has Many Purchases:
$product->purchases - Has Many Inventory:
$product->inventory
- Belongs To Product:
$purchase->product - Belongs To User:
$purchase->user
- Belongs To Product:
$sales->product - Belongs To User:
$sales->user
- Belongs To Product:
$inventory->product
All API endpoints require authentication using Laravel Sanctum. Include the Authorization: Bearer {token} header in your requests.
Register a new user.
Request Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "password",
"password_confirmation": "password",
"phone": "+1234567890" // optional
}
Response:
{
"access_token": "...",
"token_type": "Bearer"
}
Authenticate a user and receive an access token.
Request Body:
{
"email": "john@example.com",
"password": "password"
}
Response:
{
"access_token": "...",
"token_type": "Bearer"
}
Log out the authenticated user (requires Bearer token).
Response:
{
"message": "Logged out"
}
Verify a user's phone number using OTP.
Request Body:
{
"user_id": 1,
"otp": "123456"
}
Response:
{
"message": "Phone verified"
}
Verify a user's email address (link sent via email).
Response:
{
"message": "Email verified successfully"
}
Show the email verification notice (for authenticated users).
Resend the email verification notification (requires Bearer token).
Response:
{
"message": "Verification link sent"
}
Get the authenticated user's profile (requires Bearer token and verified email).
Response:
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890",
...
}
List all users with optional filtering, sorting, and searching.
Query Parameters:
filter[id]: Filter by user IDfilter[name]: Filter by namefilter[email]: Filter by emailfilter[phone]: Filter by phonesort: Sort by field (id, name, email, phone, created_at, updated_at)search: Search in name, email, phoneinclude: Include relationships (sales, purchases, roles, permissions)
Response:
{
"data": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890",
"email_verified_at": "2024-01-01T00:00:00.000000Z",
"phone_verified_at": "2024-01-01T00:00:00.000000Z",
"created_at": "2024-01-01T00:00:00.000000Z",
"updated_at": "2024-01-01T00:00:00.000000Z",
"sales": [...],
"purchases": [...],
"roles": [...],
"permissions": [...]
}
]
}Get a specific user by ID.
Update a user.
Request Body:
{
"name": "Jane Smith",
"email": "jane.smith@example.com",
"phone": "+1234567890"
}Delete a user (soft delete).
Restore a soft-deleted user.
List all products with optional filtering, sorting, and searching.
Query Parameters:
filter[id]: Filter by product IDfilter[name]: Filter by namefilter[price]: Filter by pricesort: Sort by field (id, name, price)search: Search in name, description, colorinclude: Include relationships (sales, purchases, inventory)
Create a new product.
Request Body:
{
"name": "Blue Pen",
"description": "A high-quality blue pen",
"color": "blue",
"price": 2.99,
"image_url": "https://example.com/pen.jpg"
}Get a specific product by ID.
Update a product.
Delete a product (soft delete).
Restore a soft-deleted product.
List all purchases with optional filtering, sorting, and searching.
Query Parameters:
filter[id]: Filter by purchase IDfilter[product_id]: Filter by product IDfilter[user_id]: Filter by user IDfilter[supplier]: Filter by supplierfilter[manufacturer]: Filter by manufacturerfilter[cost_per_unit]: Filter by cost per unitfilter[amount]: Filter by total amountfilter[quantity]: Filter by quantitysort: Sort by field (id, product_id, user_id, cost_per_unit, amount, quantity, created_at)search: Search in supplier, manufacturerinclude: Include relationships (product, user)
Response:
{
"data": [
{
"id": 1,
"product_id": 1,
"user_id": 1,
"supplier": "Office Supplies Co",
"manufacturer": "PenCorp",
"cost_per_unit": 1.50,
"amount": 150.00,
"quantity": 100,
"meta": {...},
"created_at": "2024-01-01T00:00:00.000000Z",
"updated_at": "2024-01-01T00:00:00.000000Z",
"product": {...},
"user": {...}
}
]
}Create a new purchase.
Request Body:
{
"product_id": 1,
"supplier": "Office Supplies Co",
"manufacturer": "PenCorp",
"cost_per_unit": 1.50,
"quantity": 100,
"meta": {
"notes": "Bulk order for office"
}
}Note: user_id will be automatically set to the authenticated user if not provided. amount will be automatically calculated as cost_per_unit * quantity if not provided.
Get a specific purchase by ID.
Update a purchase.
Delete a purchase (soft delete).
Restore a soft-deleted purchase.
List all sales with optional filtering, sorting, and searching.
Query Parameters:
filter[id]: Filter by sale IDfilter[product_id]: Filter by product IDfilter[user_id]: Filter by user IDfilter[quantity]: Filter by quantityfilter[amount]: Filter by amountfilter[action]: Filter by actionsort: Sort by field (id, product_id, user_id, quantity, amount, created_at)search: Search in actioninclude: Include relationships (product, user)
Response:
{
"data": [
{
"id": 1,
"product_id": 1,
"user_id": 1,
"quantity": 5,
"amount": 14.95,
"action": "sale",
"meta": {...},
"created_at": "2024-01-01T00:00:00.000000Z",
"updated_at": "2024-01-01T00:00:00.000000Z",
"product": {...},
"user": {...}
}
]
}Create a new sale.
Request Body:
{
"product_id": 1,
"quantity": 5,
"amount": 14.95,
"action": "sale",
"meta": {
"notes": "Walk-in customer"
}
}Note: user_id will be automatically set to the authenticated user if not provided.
Get a specific sale by ID.
Update a sale.
Delete a sale (soft delete).
Restore a soft-deleted sale.
List all inventory items with optional filtering, sorting, and searching.
Query Parameters:
filter[id]: Filter by inventory IDfilter[product_id]: Filter by product IDfilter[quantity]: Filter by quantityfilter[storage_location]: Filter by storage locationfilter[price]: Filter by price per unitfilter[last_stocked_at]: Filter by last stocked datesort: Sort by field (id, product_id, quantity, price, last_stocked_at)search: Search in storage_locationinclude: Include relationships (product)
Create a new inventory item.
Get a specific inventory item by ID.
Update an inventory item.
Delete an inventory item (soft delete).
Restore a soft-deleted inventory item.
Export inventory data to Excel format with comprehensive filtering options. This endpoint uses Laravel Actions for clean, single-purpose functionality.
Request Body (Optional Filters):
{
"product_id": 1,
"product_name": "Blue Pen",
"storage_location": "Warehouse A",
"min_quantity": 10,
"max_quantity": 1000,
"min_price": 5.00,
"max_price": 50.00,
"date_from": "2024-01-01",
"date_to": "2024-12-31"
}Filter Options:
product_id: Filter by specific product IDproduct_name: Filter by product name (partial match)storage_location: Filter by storage location (partial match)min_quantity/max_quantity: Filter by quantity rangemin_price/max_price: Filter by price per unit rangedate_from/date_to: Filter by last stocked date range
Response:
- Content-Type:
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - Content-Disposition:
attachment; filename=inventory_YYYY-MM-DD_HH-MM-SS.xlsx - File: Excel file with formatted inventory data
Excel Features:
- Professional styling with alternating row colors
- Formatted headers with blue background
- Proper column widths for readability
- Number formatting for prices and quantities
- Date formatting for timestamps
- Calculated total value column (quantity × price per unit)
- Product information included (name, description, color, price)
Implementation Details:
- Uses Laravel Actions with
AsControllertrait - Implements Laravel Excel interfaces for professional output
- Single class handles both business logic and HTTP response
- Clean, maintainable, and testable code structure
- User Assignment:
user_idis automatically set to the authenticated user for purchases and sales
All models support soft deletes, allowing data recovery through restore endpoints.
Use the include query parameter to load related data and reduce API calls.
All endpoints support filtering, sorting, and searching on relevant fields.
All endpoints are protected by policies that can be customized for your business logic.
The API returns standard HTTP status codes:
200: Success201: Created400: Bad Request401: Unauthorized403: Forbidden404: Not Found422: Validation Error500: Server Error