Files
Verde-Web/app/Models/CollectionTeam.php
admin 15f9295d34 feat(backend): complete Module 9 (teams + trucks)
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>
2026-04-30 02:48:40 +08:00

66 lines
1.5 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\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
class CollectionTeam extends Model
{
use HasFactory, SoftDeletes;
public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'inactive';
protected $fillable = [
'uuid', 'name', 'area_id', 'driver_id', 'scanner_id', 'truck_id',
'status', 'notes',
];
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 area(): BelongsTo
{
return $this->belongsTo(ServiceArea::class, 'area_id');
}
public function driver(): BelongsTo
{
return $this->belongsTo(User::class, 'driver_id');
}
public function scanner(): BelongsTo
{
return $this->belongsTo(User::class, 'scanner_id');
}
public function truck(): BelongsTo
{
return $this->belongsTo(Truck::class, 'truck_id');
}
public function members(): HasMany
{
return $this->hasMany(TeamMember::class, 'team_id');
}
public function helpers(): HasMany
{
return $this->members()->where('role_in_team', TeamMember::ROLE_HELPER);
}
}