trucks (with optional last_known_coordinates POINT 4326), collection_teams, team_members. Admin CRUD for both. TeamConflictDetector flags double-assignment of driver/scanner/truck/helper across active teams; override_conflicts: true bypasses for emergencies. Promotes routes.default_team_id to a real FK now that collection_teams exists. 144 feature tests passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
use MatanYadaev\EloquentSpatial\Objects\Point;
|
|
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
|
|
|
|
class Truck extends Model
|
|
{
|
|
use HasFactory, HasSpatial, SoftDeletes;
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
public const STATUS_MAINTENANCE = 'maintenance';
|
|
public const STATUS_RETIRED = 'retired';
|
|
|
|
protected $fillable = [
|
|
'uuid', 'plate_number', 'model', 'capacity_kg',
|
|
'assigned_team_id', 'last_known_coordinates',
|
|
'last_location_updated_at', 'status', 'notes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'last_known_coordinates' => Point::class,
|
|
'last_location_updated_at' => 'datetime',
|
|
'capacity_kg' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'uuid';
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $t): void {
|
|
if (empty($t->uuid)) $t->uuid = (string) Str::uuid();
|
|
});
|
|
}
|
|
|
|
public function assignedTeam(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CollectionTeam::class, 'assigned_team_id');
|
|
}
|
|
}
|