Skip to content

Commit a4f12ce

Browse files
author
Sebastian Fix
committed
wip
1 parent 76ff021 commit a4f12ce

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

app/Actions/ViewDataAction.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,27 @@ public function contacts(string $locale): object
4646
$key = Str::slug("contacts_published_{$locale}");
4747

4848
return Cache::rememberForever($key, function () use ($locale) {
49+
$publishedContacts = Contact::query()
50+
->where('published', true)
51+
->orderBy('name')
52+
->get();
53+
4954
return (object) collect([
5055
ContactSectionEnum::EMPLOYEE_SERVICES,
5156
ContactSectionEnum::EMPLOYEE_PRODUCTS,
5257
ContactSectionEnum::EMPLOYEE_ADMINISTRATION,
5358
ContactSectionEnum::COLLABORATIONS,
5459
ContactSectionEnum::BOARD_MEMBERS,
55-
])->mapWithKeys(function (string $section) use ($locale) {
56-
$contacts = Contact::query()
57-
->where('published', true)
58-
->whereRaw("JSON_CONTAINS_PATH(sections, 'one', '$.\"$section\"')")
59-
->orderBy('name')
60-
->get()
60+
])->mapWithKeys(function (string $section) use ($publishedContacts, $locale) {
61+
$contacts = $publishedContacts
62+
->filter(function ($contact) use ($section) {
63+
$sections = $contact->sections ?? [];
64+
65+
return array_key_exists($section, $sections);
66+
})
6167
->map(fn ($contact) => ContactDTO::fromModel($contact, $section, $locale));
6268

63-
return [$section => $contacts];
69+
return [$section => $contacts->values()];
6470
})->all();
6571
});
6672
}

0 commit comments

Comments
 (0)