*/ protected $fillable = [ 'user_id', 'subject_id', 'is_active', 'frequency', 'preferred_times', 'weekdays', 'insight_language', 'delivery_channels', ]; /** @var array */ protected $casts = [ 'is_active' => 'boolean', 'weekdays' => 'array', 'preferred_times' => 'array', 'delivery_channels' => 'array', ]; /** * Get default delivery channels. */ public static function getDefaultChannels(): array { return ['dashboard']; } /** * Check if a specific delivery channel is enabled. */ public function hasChannel(string $channel): bool { $channels = $this->delivery_channels ?? self::getDefaultChannels(); return in_array($channel, $channels, true); } /** * Get the user associated with this user subject. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * Get the subject associated with this user subject. */ public function subject(): BelongsTo { return $this->belongsTo(Subject::class); } /** * Get the preferred times as a formatted string for display. */ public function getFormattedTimesAttribute(): string { if (empty($this->preferred_times)) { return __('Any time'); } $times = collect($this->preferred_times) ->map(fn ($time) => substr($time, 0, 5)) ->implode(', '); return $times; } }