diff --git a/app/Nova/GirlsInDigitalFaqItem.php b/app/Nova/GirlsInDigitalFaqItem.php index 40d6cc61a..ee7baa4dc 100644 --- a/app/Nova/GirlsInDigitalFaqItem.php +++ b/app/Nova/GirlsInDigitalFaqItem.php @@ -37,6 +37,21 @@ public static function uriKey(): string /** Only manage FAQ items from the Girls in Digital page (HasMany). */ public static $displayInNavigation = false; + public static function authorizedToCreate(Request $request): bool + { + return true; + } + + public static function authorizedToUpdate(Request $request, $model): bool + { + return true; + } + + public static function authorizedToDelete(Request $request, $model): bool + { + return true; + } + private static function localesSorted(): array { $locales = config('app.locales', ['en']); @@ -95,7 +110,12 @@ public function fields(Request $request): array $fields = [ ID::make()->onlyOnForms(), \Laravel\Nova\Fields\Hidden::make('Page', 'page_id') - ->default(fn ($request) => $request->viaResourceId ?? 1), + ->default(function ($request) { + if ($request instanceof \Laravel\Nova\Http\Requests\NovaRequest && method_exists($request, 'viaResourceId')) { + return $request->viaResourceId() ?? 1; + } + return $request->query('viaResourceId', 1); + }), Text::make('Question (default)', 'question')->nullable()->rules('nullable', 'string'), Trix::make('Answer (default)', 'answer')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), \Laravel\Nova\Fields\Number::make('Order', 'position')->min(0)->help('Lower numbers appear first.'), diff --git a/app/Nova/GirlsInDigitalPage.php b/app/Nova/GirlsInDigitalPage.php index ff8f5084f..82b5f5505 100644 --- a/app/Nova/GirlsInDigitalPage.php +++ b/app/Nova/GirlsInDigitalPage.php @@ -268,7 +268,7 @@ private function buildFields(Request $request): array Panel::make('Section toggles', [ \Laravel\Nova\Fields\Heading::make('Turn on "Use dynamic content" in each section below to show DB content on the front.'), - ])->collapsable(), + ])->collapsable()->collapsedByDefault(), Panel::make('Hero', $heroFields)->collapsable()->collapsedByDefault(), @@ -328,18 +328,22 @@ public static function afterSave(NovaRequest $request, $model): void $allKeys = self::allButtonKeys(); $positionMap = array_flip($allKeys); foreach ($updates as $key => $fields) { - $existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first(); - $payload = [ - 'label' => array_key_exists('label', $fields) ? (string) $fields['label'] : ($existing?->label ?? ''), - 'url' => array_key_exists('url', $fields) ? (string) $fields['url'] : ($existing?->url ?? '#'), - 'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false), - 'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true), - 'position' => $positionMap[$key] ?? $existing?->position ?? 0, - ]; - GirlsInDigitalButton::updateOrCreate( - ['page_id' => $model->id, 'key' => $key], - $payload - ); + try { + $existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first(); + $payload = [ + 'label' => array_key_exists('label', $fields) ? (string) $fields['label'] : ($existing?->label ?? ''), + 'url' => array_key_exists('url', $fields) ? (string) $fields['url'] : ($existing?->url ?? '#'), + 'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false), + 'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true), + 'position' => $positionMap[$key] ?? $existing?->position ?? 0, + ]; + GirlsInDigitalButton::updateOrCreate( + ['page_id' => $model->id, 'key' => $key], + $payload + ); + } catch (\Throwable $e) { + report($e); + } } unset($model->_button_updates); } catch (\Throwable $e) {