Skip to content

Carrier Model

Multi-tenant carrier/organization that manages members and products.

Overview

The Carrier model is the central entity in the multi-tenant system, representing organizations that manage members, products, and shopping carts. Each carrier operates independently with their own data isolation.

Attributes

AttributeTypeDescription
idintPrimary key
namestringCarrier name
slugstringURL-friendly identifier
domainstringCarrier domain
descriptiontextCarrier description
logo_urlstringLogo image URL
is_activebooleanActive status flag
settingsjsonJSON configuration settings
created_attimestampCreation timestamp
updated_attimestampLast update timestamp
deleted_attimestampSoft delete timestamp

Relationships

Has Many

  • hasMany(Member) - Carrier's members
  • hasMany(Cart) - Carrier's shopping carts
  • hasMany(Order) - Carrier's orders

Key Features

Multi-Tenancy

  • Central multi-tenant entity
  • Data isolation between carriers
  • Independent carrier operations

Branding & Customization

  • Custom domain support
  • Logo and branding management
  • Carrier-specific settings

Search Integration

  • MeiliSearch integration for name and slug search
  • Fast carrier lookup
  • Searchable carrier profiles

Data Management

  • Soft deletes for data retention
  • Active carrier scope filtering
  • Flexible settings storage

Usage Examples

Creating a Carrier

php
$carrier = Carrier::create([
    'name' => 'ABC Health Insurance',
    'slug' => 'abc-health',
    'domain' => 'abc.otcplatform.com',
    'description' => 'Leading health insurance provider',
    'logo_url' => 'https://example.com/logo.png',
    'is_active' => true,
    'settings' => [
        'prescription_required' => true,
        'max_cart_items' => 50,
        'shipping_enabled' => true
    ]
]);

Getting Associated Data

php
// Get carrier's members
$members = $carrier->members;

// Get carrier's carts
$carts = $carrier->carts;

// Get carrier's orders
$orders = $carrier->orders;

// Get active members
$activeMembers = $carrier->members()->active()->get();

Searching Carriers

php
// Search by name or slug
$carriers = Carrier::search('health insurance')->get();

// Get active carriers
$activeCarriers = Carrier::active()->get();

// Get carrier by slug
$carrier = Carrier::where('slug', 'abc-health')->first();

Scopes

Active Carriers

php
// Get only active carriers
Carrier::active()->get();

By Domain

php
// Get carrier by domain
Carrier::where('domain', $domain)->first();

Route Key

The Carrier model uses the slug as the route key for URL-friendly routing:

php
// Route model binding uses slug
Route::get('/carriers/{carrier}', function (Carrier $carrier) {
    return $carrier;
});

Settings Management

Carriers can store custom settings as JSON:

php
// Set carrier settings
$carrier->settings = [
    'prescription_required' => true,
    'max_cart_items' => 50,
    'shipping_enabled' => true,
    'tax_rate' => 0.08
];
$carrier->save();

// Get specific setting
$maxItems = $carrier->settings['max_cart_items'] ?? 25;
  • Member - Carrier's members
  • Cart - Shopping cart functionality
  • Order - Order management
  • Product - Product management