$ids * * @return Collection */ public static function fromModels(array $ids): Collection { return Member::whereIn('id', $ids)->orderByRaw('lastname, firstname')->get()->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([ ...$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::factory()->withoutMagicalCreation()->from([ ...$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 city(): string { return $this->zip . ' ' . $this->location; } public function age(): string { return $this->birthday ? intval($this->birthday->diffInYears(now())) : ''; } public function birthYear(): string { return (string) $this->birthday->year; } public function birthdayHuman(): string { return $this->birthday->format('d.m.Y'); } public function genderLetter(): string { return $this->gender->short; } }