$ids * * @return Collection */ public static function fromModels(array $ids): Collection { return Member::whereIn('id', $ids)->orderByRaw('lastname, firstname')->get()->map(fn ($member) => self::withoutMagicalCreationFrom([ ...$member->toArray(), 'birthday' => $member->birthday->toAtomString(), 'isLeader' => $member->isLeader(), 'gender' => $member->gender, ]))->toBase(); } /** * @param array $data * * @return Collection */ public static function fromApi(array $data): Collection { return collect($data)->map(fn ($member) => self::withoutMagicalCreationFrom([ ...$member, 'birthday' => Carbon::parse($member['birthday'])->toAtomString(), 'gender' => Gender::fromString($member['gender']), 'isLeader' => $member['is_leader'], ])); } public function fullname(): string { return $this->firstname.' '.$this->lastname; } public function separatedName(): string { return $this->lastname.', '.$this->firstname; } public function fullAddress(): string { return $this->address.', '.$this->zip.' '.$this->location; } public function age(): string { return (string) $this->birthday->diffInYears(now()) ?: ''; } }