'datetime', 'new_trial_ends_at' => 'datetime', 'granted_at' => 'datetime', 'metadata' => 'array', ]; protected $dates = [ 'original_trial_ends_at', 'new_trial_ends_at', 'granted_at', ]; /** * Relationships */ public function subscription() { return $this->belongsTo(Subscription::class); } public function user() { return $this->belongsTo(User::class); } public function grantedByAdmin() { return $this->belongsTo(User::class, 'granted_by_admin_id'); } /** * Get human-readable extension type */ public function getExtensionTypeLabelAttribute(): string { return [ 'manual' => 'Manual Grant', 'automatic' => 'Automatic Extension', 'compensation' => 'Compensation', ][$this->extension_type] ?? ucfirst($this->extension_type); } /** * Scope: By extension type */ public function scopeByType($query, string $type) { return $query->where('extension_type', $type); } /** * Scope: By user */ public function scopeByUser($query, $userId) { return $query->where('user_id', $userId); } /** * Scope: Granted by admin */ public function scopeGrantedBy($query, $adminId) { return $query->where('granted_by_admin_id', $adminId); } /** * Scope: Within date range */ public function scopeBetweenDates($query, $startDate, $endDate) { return $query->whereBetween('granted_at', [$startDate, $endDate]); } }