Files
hub/app/Models/Driver.php
Jon Leopard 7e5ea2bc10 checkpoint: marketplace and operational features complete, ready for Week 4 data migration
Summary of completed work:
- Complete buyer portal (browse, cart, checkout, orders, invoices)
- Complete seller portal (orders, manifests, fleet, picking)
- Business onboarding wizards (buyer 4-step, seller 5-step)
- Email verification and registration flows
- Notification system for buyers and sellers
- Payment term surcharges and pickup/delivery workflows
- Filament admin resources (Business, Brand, Product, Order, Invoice, User)
- 51 migrations executed successfully

Renamed Company -> Business throughout codebase for consistency.
Unified authentication flows with password reset.
Added audit trail and telescope for debugging.

Next: Week 4 Data Migration (Days 22-28)
- Product migration (883 products from cannabrands_crm)
- Company migration (81 buyer companies)
- User migration (preserve password hashes)
- Order history migration
2025-10-15 11:17:15 -07:00

103 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Driver extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'business_id',
'first_name',
'last_name',
'license_number',
'phone',
'email',
'transporter_id',
'is_active',
'created_by',
];
protected $casts = [
'is_active' => 'boolean',
];
/**
* Relationships
*/
public function business(): BelongsTo
{
return $this->belongsTo(Business::class, 'business_id');
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
public function manifests(): HasMany
{
return $this->hasMany(Manifest::class);
}
/**
* Scopes
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function scopeForCompany($query, int $companyId)
{
return $query->where('business_id', $companyId);
}
/**
* Helper Methods
*/
/**
* Get driver's first name.
*/
public function getFirstName(): string
{
return $this->first_name ?? '';
}
/**
* Get driver's last initial.
*/
public function getLastInitial(): string
{
return $this->last_name ? strtoupper(substr($this->last_name, 0, 1)) : '';
}
/**
* Get full name.
*/
public function getFullNameAttribute(): string
{
return trim($this->first_name . ' ' . $this->last_name);
}
/**
* Get display name for dropdowns.
*/
public function getDisplayNameAttribute(): string
{
return "{$this->full_name} (License: {$this->license_number})";
}
}