Skip to content

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

AttributeTypeDescription
idintPrimary key
uuidstringUnique identifier for routing
namestringProduct name
descriptiontextProduct description
colorstringProduct color
priceintPrice in cents
image_urlstringProduct image URL
is_availablebooleanAvailability flag
inventory_countintStock quantity
skustringStock keeping unit

Medical/Pharmaceutical Fields

AttributeTypeDescription
strengthstringDrug strength
dosage_formstringForm of medication
quantitystringQuantity per unit
active_ingredientstringActive ingredient
requires_prescriptionbooleanPrescription required flag
drug_classstringDrug classification
storage_conditionsstringStorage requirements
expiry_datedateExpiration date
ndc_numberstringNational Drug Code
rxnorm_idstringRxNorm identifier
metadatajsonAdditional JSON data

Timestamps

AttributeTypeDescription
created_attimestampCreation timestamp
updated_attimestampLast update timestamp

Relationships

Belongs To

Has Many

  • hasMany(ProductSpecificationValue) - Product specifications
  • hasMany(Categorizable) - Product categorizations
  • hasMany(OrderItem) - Product order items

Belongs To Many

  • belongsToMany(ProductSpecification) - Product specifications (via pivot)
  • belongsToMany(Category) - Product categories (via Categorizable)

Key Features

Categorization System

  • Uses HasCategorizations trait
  • 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 products

Medical Scopes

php
Product::byDrugClass('NSAIDs')           // Products by drug class
Product::byActiveIngredient('Ibuprofen') // Products by active ingredient

Accessors

Price Formatting

php
$product->formatted_price; // Returns "$12.99"
$product->min_price;       // Minimum price for variants
$product->max_price;       // Maximum price for variants

Inventory Accessors

php
$product->total_inventory;     // Total inventory across variants
$product->available_inventory; // Available inventory
$product->has_variants;        // Boolean for variant existence

Availability Accessors

php
$product->effective_availability; // Overall availability status

Route 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;
});