, * summary_text: string, * body?: list, * html?: string, * editor: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null}|null, * co_editor: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null}|null, * etag: string, * abilities: array{update: bool, delete: bool}, * created_at: string, * updated_at: string, * deleted_at: string|null * } */ public function toArray(Request $request): array { $tag = trim((string) $this->tag); return [ 'id' => (string) $this->guid, 'word' => (string) $this->word, 'tag' => $tag === '' ? null : $tag, 'meaning' => (string) $this->meaning, 'other_meaning' => $this->other_meaning, 'language' => (string) $this->language, 'channel_id' => $this->channal, 'channel' => $this->channel ? ['id' => (string) $this->channel->uid, 'name' => (string) $this->channel->name] : null, 'owner_id' => (string) $this->owner, 'quality' => $this->quality, 'content_type' => $this->effectiveContentType(), 'summary' => $this->summary, 'note' => $this->note, 'redirect' => $this->redirect !== '' ? $this->redirect : null, 'categories' => $this->categories->pluck('category')->values()->all(), 'summary_text' => (string) ($this->summary_text ?? ''), 'body' => $this->when(isset($this->body), fn () => $this->body), 'html' => $this->when(isset($this->html), fn () => $this->html), 'editor' => $this->actor($this->user, $this->aiModel), 'co_editor' => $this->coEditor ? $this->actor(null, $this->coEditor) : null, 'etag' => $this->etag(), 'abilities' => [ 'update' => (bool) ($this->abilities['update'] ?? false), 'delete' => (bool) ($this->abilities['delete'] ?? false), ], 'created_at' => $this->created_at?->toIso8601ZuluString(), 'updated_at' => $this->updated_at?->toIso8601ZuluString(), 'deleted_at' => $this->deleted_at?->toIso8601ZuluString(), ]; } /** * 单条响应带 ETag 头(列表不带)。 */ public function withResponse(Request $request, JsonResponse $response): void { $response->header('ETag', $this->etag()); } }