attributes->get('user'); } /** Событие по `id` из аргументов; чужое или несуществующее — ошибка для модели, а не 500. */ protected function withEvent(Request $request, Closure $then): Response|ResponseFactory { $id = (int) $request->validate(['id' => ['required', 'integer']])['id']; try { $event = $this->user()->ownEvent($id); } catch (ModelNotFoundException) { return Response::error('Событие не найдено'); } return $then($event); } /** То же, но только своё (manual) событие — для правки и снятия. */ protected function withOwnEvent(Request $request, Closure $then): Response|ResponseFactory { return $this->withEvent($request, fn (Event $event) => ManualEvents::owns($event) ? $then($event) : Response::error("Это событие источника {$event->source->name}: правит и снимает его только источник. Можно закрыть через mark_done.")); } /** @param array $data */ protected function respond(array $data): ResponseFactory { return Response::structured($data); } }