*/ public function toArray(Request $request): array { $locale = $request->query(config('locales.query_parameter')) ?? app()->getLocale(); return [ 'id' => $this->id, 'locale' => $locale, 'name' => $this->name, 'slug' => $this->slug, ...TranslatablePayload::resolve($this->resource, $this->translatable, $locale), 'avatar' => $this->avatar, 'avatar_media' => ImagePayload::make( $this->avatar, $this->resource->relationLoaded('avatarMedia') ? $this->resource->getRelation('avatarMedia') : null, $this->name, ), 'email' => $this->email, 'github_username' => $this->github_username, 'links' => (object) ($this->links ?? []), 'is_public' => (bool) $this->is_public, 'is_founder' => (bool) $this->is_founder, 'joined_at' => $this->joined_at?->toDateString(), 'left_at' => $this->left_at?->toDateString(), 'position' => $this->position, 'technology_ids' => $this->whenLoaded('technologies', fn () => $this->technologies->pluck('id')->values()), 'projects' => $this->whenLoaded('projects', fn () => $this->projects->map(fn ($project) => [ 'id' => $project->id, 'title' => $project->getTranslation('title', $locale), 'role' => $project->pivot->role, ])->values()), '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), ), ]; } }