ReportStatus::class, 'period_start' => 'date', 'period_end' => 'date', ]; } // --- Relationships --- public function project(): BelongsTo { return $this->belongsTo(Project::class); } public function workforceMetric(): HasOne { return $this->hasOne(WorkforceMetric::class); } public function hseRecord(): HasOne { return $this->hasOne(HseRecord::class); } public function submitter(): BelongsTo { return $this->belongsTo(User::class, 'submitted_by'); } public function approver(): BelongsTo { return $this->belongsTo(User::class, 'approved_by'); } // --- State Machine --- public function transitionTo(ReportStatus $newStatus): void { if (!in_array($newStatus, $this->status->allowedTransitions())) { throw new \InvalidArgumentException( "Cannot transition report from {$this->status->label()} to {$newStatus->label()}" ); } $this->update(['status' => $newStatus]); } // --- Scopes --- public function scopeStatus($query, ReportStatus $status) { return $query->where('status', $status); } public function scopeApproved($query) { return $query->where('status', ReportStatus::Approved); } // --- Accessors --- public function getPeriodLabelAttribute(): string { return $this->period_start->format('M d') . ' – ' . $this->period_end->format('M d, Y'); } public function getDaysInPeriodAttribute(): int { return $this->period_start->diffInDays($this->period_end) + 1; } }