*/ public function toArray(Request $request): array { $locale = $request->query(config('locales.query_parameter')) ?? app()->getLocale(); return [ 'id' => $this->id, 'locale' => $locale, ...TranslatablePayload::resolve($this->resource, $this->translatable, $locale), 'original_locale' => $this->original_locale, 'author_name' => $this->author_name, 'avatar' => $this->avatar, 'avatar_media' => ImagePayload::make( $this->avatar, $this->resource->relationLoaded('avatarMedia') ? $this->resource->getRelation('avatarMedia') : null, $this->author_name, ), 'client_id' => $this->client_id, 'project_id' => $this->project_id, 'service_id' => $this->service_id, 'is_public' => (bool) $this->is_public, 'position' => $this->position, 'given_at' => $this->given_at?->toDateString(), 'created_at' => $this->created_at?->toIso8601String(), 'updated_at' => $this->updated_at?->toIso8601String(), 'deleted_at' => $this->deleted_at?->toIso8601String(), 'translations' => $this->when( in_array('translations', explode(',', (string) $request->query('with')), true), fn () => TranslatablePayload::all($this->resource, $this->translatable), ), ]; } }