hasMany(Channel::class); } public function events(): HasMany { return $this->hasMany(Event::class); } /** Событие пользователя по id; чужой id — «не найдено», а не 403. */ public function ownEvent(int $id): Event { return $this->events()->with('source')->whereKey($id)->firstOrFail(); } /** Закрытые события для архива: done и expired, свежие первыми, не больше 100. */ public function archive(): HasMany { return $this->events()->with('source') ->whereIn('state', [EventState::Done->value, EventState::Expired->value]) ->orderByDesc('updated_at')->limit(100); } /** «Сейчас» в поясе пользователя. */ public function now(): CarbonImmutable { return CarbonImmutable::now($this->tz); } /** Начало активных часов в данный календарный день. */ public function activeStart(CarbonImmutable $day): CarbonImmutable { return $day->startOfDay()->setTimeFromTimeString($this->quiet_end); } /** Конец активных часов (начало тихих) в данный календарный день. */ public function activeEnd(CarbonImmutable $day): CarbonImmutable { return $day->startOfDay()->setTimeFromTimeString($this->quiet_start); } }