'date', 'end_date' => 'date', 'coaches' => 'array', ]; /** * Get the member that owns the affiliation. */ public function member(): BelongsTo { return $this->belongsTo(User::class, 'member_id'); } /** * Get the skills acquired during this affiliation. */ public function skillAcquisitions(): HasMany { return $this->hasMany(SkillAcquisition::class); } /** * Get the media associated with this affiliation. */ public function affiliationMedia(): HasMany { return $this->hasMany(AffiliationMedia::class); } /** * Get the subscriptions associated with this affiliation. */ public function subscriptions(): HasMany { return $this->hasMany(ClubMemberSubscription::class, 'club_affiliation_id'); } /** * Get the packages through subscriptions. */ public function packages() { return $this->hasManyThrough( ClubPackage::class, ClubMemberSubscription::class, 'club_affiliation_id', // Foreign key on subscriptions table 'id', // Foreign key on packages table 'id', // Local key on affiliations table 'package_id' // Local key on subscriptions table ); } /** * Get the duration of the affiliation in months. */ public function getDurationInMonthsAttribute(): int { $endDate = $this->end_date ?? now(); return $this->start_date->diffInMonths($endDate); } /** * Get formatted date range. */ public function getDateRangeAttribute(): string { $start = $this->start_date->format('M Y'); $end = $this->end_date ? $this->end_date->format('M Y') : 'Present'; return $start . ' – ' . $end; } /** * Get detailed formatted duration (years, months, days). */ public function getFormattedDurationAttribute(): string { $endDate = $this->end_date ?? now(); $diff = $this->start_date->diff($endDate); $parts = []; if ($diff->y > 0) { $parts[] = $diff->y . ' year' . ($diff->y > 1 ? 's' : ''); } if ($diff->m > 0) { $parts[] = $diff->m . ' month' . ($diff->m > 1 ? 's' : ''); } if ($diff->d > 0) { $parts[] = $diff->d . ' day' . ($diff->d > 1 ? 's' : ''); } return implode(' ', $parts) ?: 'Same day'; } }