Product Model
Core product model with medical/pharmaceutical specific fields and categorization support.
Overview
The Product model is the central entity for managing pharmaceutical and medical products. It includes comprehensive medical/pharmaceutical fields, inventory management, categorization support, and search capabilities.
Attributes
Basic Product Fields
| Attribute | Type | Description |
|---|---|---|
id | int | Primary key |
uuid | string | Unique identifier for routing |
name | string | Product name |
description | text | Product description |
color | string | Product color |
price | int | Price in cents |
image_url | string | Product image URL |
is_available | boolean | Availability flag |
inventory_count | int | Stock quantity |
sku | string | Stock keeping unit |
Medical/Pharmaceutical Fields
| Attribute | Type | Description |
|---|---|---|
strength | string | Drug strength |
dosage_form | string | Form of medication |
quantity | string | Quantity per unit |
active_ingredient | string | Active ingredient |
requires_prescription | boolean | Prescription required flag |
drug_class | string | Drug classification |
storage_conditions | string | Storage requirements |
expiry_date | date | Expiration date |
ndc_number | string | National Drug Code |
rxnorm_id | string | RxNorm identifier |
metadata | json | Additional JSON data |
Timestamps
| Attribute | Type | Description |
|---|---|---|
created_at | timestamp | Creation timestamp |
updated_at | timestamp | Last update timestamp |
Relationships
Belongs To
Has Many
hasMany(ProductSpecificationValue)- Product specificationshasMany(Categorizable)- Product categorizationshasMany(OrderItem)- Product order items
Belongs To Many
belongsToMany(ProductSpecification)- Product specifications (via pivot)belongsToMany(Category)- Product categories (via Categorizable)
Key Features
Categorization System
- Uses
HasCategorizationstrait - Multiple categorization types (drug_class, therapeutic_category, etc.)
- Flexible category assignment
Search Integration
- MeiliSearch integration for comprehensive search
- Searchable product attributes
- Fast product lookup
Inventory Management
- Stock quantity tracking
- Availability status
- Inventory calculations
Medical/Pharmaceutical Features
- Prescription requirement tracking
- Drug classification
- Storage condition management
- Expiration date tracking
Price Management
- Price in cents for precision
- Formatted price accessors
- Price range calculations
Usage Examples
Creating a Product
php
$product = Product::create([
'uuid' => Str::uuid(),
'name' => 'Advil 200mg Tablets',
'description' => 'Ibuprofen pain reliever',
'price' => 1299, // $12.99 in cents
'is_available' => true,
'inventory_count' => 100,
'sku' => 'ADV-200-30',
'strength' => '200mg',
'dosage_form' => 'tablet',
'quantity' => '30 tablets',
'active_ingredient' => 'Ibuprofen',
'requires_prescription' => false,
'drug_class' => 'NSAIDs',
'storage_conditions' => 'Store at room temperature',
'metadata' => [
'generic_name' => 'Ibuprofen',
'brand_name' => 'Advil'
]
]);Categorizing Products
php
// Add to drug class category
$product->attachCategory($nsaidsCategory->id, 'drug_class');
// Add to therapeutic category
$product->attachCategory($painReliefCategory->id, 'therapeutic_category');
// Get categories by type
$drugClassCategories = $product->categoriesOfType('drug_class');Searching Products
php
// Search by name, description, or ingredients
$products = Product::search('ibuprofen pain relief')->get();
// Get available products
$availableProducts = Product::available()->get();
// Get products in stock
$inStockProducts = Product::inStock()->get();
// Get prescription products
$prescriptionProducts = Product::prescription()->get();
// Get OTC products
$otcProducts = Product::otc()->get();Scopes
Availability Scopes
php
Product::available() // Only available products
Product::inStock() // Products with inventory > 0
Product::prescription() // Products requiring prescription
Product::otc() // Over-the-counter productsMedical Scopes
php
Product::byDrugClass('NSAIDs') // Products by drug class
Product::byActiveIngredient('Ibuprofen') // Products by active ingredientAccessors
Price Formatting
php
$product->formatted_price; // Returns "$12.99"
$product->min_price; // Minimum price for variants
$product->max_price; // Maximum price for variantsInventory Accessors
php
$product->total_inventory; // Total inventory across variants
$product->available_inventory; // Available inventory
$product->has_variants; // Boolean for variant existenceAvailability Accessors
php
$product->effective_availability; // Overall availability statusRoute Key
The Product model uses the uuid as the route key for secure routing:
php
// Route model binding uses UUID
Route::get('/products/{product}', function (Product $product) {
return $product;
});Related Models
- Category - Product categories
- Categorizable - Categorization relationships
- OrderItem - Order items