Skip to content
Merged

Dev #3330

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,16 @@ public function getButtonsForLocale(?string $locale = null): Collection
*/
public function faqItemsForLocale(?string $locale = null): array
{
return $this->faqItems->map(fn (GirlsInDigitalFaqItem $item) => [
'question' => $item->questionForLocale($locale),
'answer' => $item->answerForLocale($locale),
])->all();
try {
if (! \Illuminate\Support\Facades\Schema::hasTable('girls_in_digital_faq_items')) {
return [];
}
return $this->faqItems->map(fn (GirlsInDigitalFaqItem $item) => [
'question' => $item->questionForLocale($locale),
'answer' => $item->answerForLocale($locale),
])->all();
} catch (\Throwable $e) {
return [];
}
}
}
21 changes: 16 additions & 5 deletions app/Nova/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ public function fields(Request $request): array
}
$faqFields[] = $this->localeField('FAQ title (' . strtoupper($locale) . ')', $locale, 'faq_title', false);
}
$faqFields[] = HasMany::make('FAQ items', 'faqItems', GirlsInDigitalFaqItem::class)
->help('Add, edit, or reorder FAQ items. Each item has a question and answer (with formatting). Use the Translations panel on each item for other languages.');
if (Schema::hasTable('girls_in_digital_faq_items')) {
$faqFields[] = HasMany::make('FAQ items', 'faqItems', GirlsInDigitalFaqItem::class)
->help('Add, edit, or reorder FAQ items. Each item has a question and answer (with formatting). Use the Translations panel on each item for other languages.');
} else {
$faqFields[] = \Laravel\Nova\Fields\Heading::make('Run migration to enable FAQ items: php artisan migrate --path=database/migrations/2026_02_12_100000_create_girls_in_digital_faq_items_table.php');
}

return [
ID::make()->onlyOnForms(),
Expand All @@ -264,11 +268,18 @@ public function fields(Request $request): array

private function getButtonField(string $key, string $field)
{
$button = $this->resource->buttons()->where('key', $key)->first();
if (! $button) {
try {
if (! \Illuminate\Support\Facades\Schema::hasTable('girls_in_digital_buttons')) {
return $field === 'enabled' ? true : ($field === 'open_new_tab' ? false : '');
}
$button = $this->resource->buttons()->where('key', $key)->first();
if (! $button) {
return $field === 'enabled' ? true : ($field === 'open_new_tab' ? false : '');
}
return $button->{$field};
} catch (\Throwable $e) {
return $field === 'enabled' ? true : ($field === 'open_new_tab' ? false : '');
}
return $button->{$field};
}

private function fillButtonField(\App\GirlsInDigitalPage $model, string $key, string $field, $value): void
Expand Down
Loading