'date', 'start_date' => 'date', 'status' => LeaveRequestStatus::class, 'total_days' => 'integer', 'verified_at' => 'datetime', ]; } // 3. Scope (grouped by column, then alphabetical) // Column Group: status #[Scope] protected function approved(Builder $query): void { $query->where('status', LeaveRequestStatus::APPROVED); } #[Scope] protected function pending(Builder $query): void { $query->where('status', LeaveRequestStatus::PENDING); } #[Scope] protected function rejected(Builder $query): void { $query->where('status', LeaveRequestStatus::REJECTED); } // 4. Attribute public function canVerify(): Attribute { return Attribute::make( get: fn () => $this->status === LeaveRequestStatus::PENDING, ); } public function createdAtFormatted(): Attribute { return Attribute::make( get: fn () => $this->created_at?->translatedFormat('l, d F Y H:i'), ); } public function employeeName(): Attribute { return Attribute::make( get: fn () => $this->employee?->user?->profile?->full_name ?? $this->employee?->user?->username, ); } public function endDateFormatted(): Attribute { return Attribute::make( get: fn () => $this->end_date?->translatedFormat('l, d F Y'), ); } public function endDateInput(): Attribute { return Attribute::make( get: fn () => $this->end_date?->format('Y-m-d'), ); } public function isEditable(): Attribute { return Attribute::make( get: fn () => $this->status === LeaveRequestStatus::PENDING, ); } public function rejectionReason(): Attribute { return Attribute::make( get: fn () => $this->rejection?->reason, ); } public function startDateFormatted(): Attribute { return Attribute::make( get: fn () => $this->start_date?->translatedFormat('l, d F Y'), ); } public function startDateInput(): Attribute { return Attribute::make( get: fn () => $this->start_date?->format('Y-m-d'), ); } public function statusLabel(): Attribute { return Attribute::make( get: fn () => $this->status?->label(), ); } // 5. Other Methods public function ensureEditable(): void { if ($this->status !== LeaveRequestStatus::PENDING) { throw ValidationException::withMessages([ 'status' => 'Pengajuan cuti tidak dapat diubah.', ]); } } public static function canSubmit(User $user): bool { return $user->can(Permission::LEAVE_REQUESTS_CREATE->value) && ! $user->can(Permission::LEAVE_REQUESTS_VERIFY->value) && $user->employee !== null; } // 6. Relation public function employee(): BelongsTo { return $this->belongsTo(Employee::class); } public function verifiedBy(): BelongsTo { return $this->belongsTo(User::class, 'verified_by_id'); } }