Model Conventions
- UUID Primary Keys: All models use UUID via
HasUuidtrait - Tenant Isolation:
BelongsToTenanttrait ensures data segregation - Soft Deletes: Most models support soft deletion for data recovery
- Explicit Query Builder: Always use
Model::query()->prefix
Product
Represents a product in the inventory system. Products can have multiple variants (sizes, colors) or be standalone items. Location:app/Models/Product.php
Properties
Primary key
Tenant owner
Shop location
Product type (General, Pharmacy, Retail, etc.)
Product category
Product name
URL-friendly identifier (unique per tenant)
Product description
Type-specific attributes (e.g., requires_prescription for pharmacy)
Whether product has multiple variants
Product visibility status
Enable inventory tracking
Subject to VAT
Featured on storefront
Relationships
Tenant that owns this product
Shop where product is sold
Product type definition
Product category
Product variants (sizes, colors, etc.)
Product images
State Management
is_active vs Soft Deletes
is_active vs Soft Deletes
Products use BOTH
Use is_active = false for:
is_active flag AND soft deletes for different purposes:| State | is_active | deleted_at | Behavior |
|---|---|---|---|
| Active | true | null | Fully visible: POS, Storefront, Admin, Reports |
| Inactive | false | null | Hidden from POS/Storefront, visible in Admin/Reports |
| Deleted | N/A | timestamp | Completely hidden, can be restored via soft delete recovery |
- Temporarily disable sales (out of season, pending restock)
- Hide from customer-facing channels without losing data
- Permanently remove from all active operations
- Discontinue product while preserving historical order data
Scopes
Example
Order
Represents a customer order with status tracking, payments, and fulfillment workflow. Location:app/Models/Order.php
Properties
Primary key
Tenant owner
Shop location
Customer (optional for guest orders)
Auto-generated unique order number (ORD-YYYYMMDD-####)
POS, CUSTOMER, or INTERNAL
Current order status
Payment status (UNPAID, PARTIAL, PAID, REFUNDED)
Sum of line items before tax and shipping
Total tax amount
Total discount applied
Shipping cost
Final total including tax and shipping
Amount paid so far
Relationships
Tenant that owns this order
Shop where order was placed
Customer who placed the order
Order line items
Payment records
Return records
Generated receipts
Methods
Check if order can be edited (PENDING or CONFIRMED status)
Check if order can be cancelled (not DELIVERED, CANCELLED, or REFUNDED)
Recalculate order totals from items
Get unpaid balance
Check if order is completely paid
Scopes
Example
Customer
Represents an e-commerce customer (separate from User model which represents staff). Location:app/Models/Customer.php
Properties
Primary key
Tenant owner
Default shop for customer
Customer first name
Customer last name
Customer email (unique per tenant)
Customer phone number
Account active status
Marketing communications consent
Current balance (for credit accounts)
Maximum credit allowed
Lifetime purchase total
Relationships
Tenant that owns this customer
Customer’s preferred shop
Customer addresses
Customer orders
Shopping carts
Credit transaction history
Methods
Get remaining credit available
Check if customer can make a purchase on credit
Get all orders with unpaid or partial payment status
Scopes
Example
Shop
Represents a physical or virtual store location within a tenant. Location:app/Models/Shop.php
Properties
Primary key
Tenant owner
Shop type (Retail, Restaurant, Pharmacy, etc.)
Shop name
URL-friendly identifier
Type-specific configuration
Inventory tracking model (PERPETUAL, PERIODIC)
Shop active status
Enable e-commerce storefront
Storefront configuration (shipping, theme, etc.)
Shop currency code
Currency symbol
Enable VAT calculations
VAT rate percentage
Relationships
Tenant that owns this shop
Shop type definition
Staff assigned to this shop
Products sold at this shop
Services offered at this shop
Shopping carts for this shop
Shop-specific tax settings
Example
Additional Models
- ProductVariant
- OrderItem
- StockMovement
- PayRun
Location:
app/Models/ProductVariant.phpRepresents a specific variant of a product (size, color, etc.)Key Properties
product_id- Parent productsku- Stock Keeping Unit (unique)barcode- Barcode numbername- Variant name (e.g., “Large”, “Red”)attributes- Variant attributes JSONprice- Selling pricecost_price- Purchase costbase_unit_name- Base unit (e.g., “Pack”, “Bottle”)reorder_level- Minimum stock level
Relationships
product- Parent productpackagingTypes- Available packaging optionsinventoryLocations- Stock levels per location
Query Best Practices
Always Use Query Builder
Always Use Query Builder
Tenant Isolation
Tenant Isolation
Eager Loading
Eager Loading
Soft Deletes
Soft Deletes