From 18b80cc7ae6ea420f2af29f7bd7a584585852a56 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 20 Nov 2023 18:17:22 +0000 Subject: [PATCH] Create tree for navigation if one doesn't exist --- src/Http/Controllers/CP/Navigation/NavigationController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Http/Controllers/CP/Navigation/NavigationController.php b/src/Http/Controllers/CP/Navigation/NavigationController.php index 0854b2b095..11537dd73e 100644 --- a/src/Http/Controllers/CP/Navigation/NavigationController.php +++ b/src/Http/Controllers/CP/Navigation/NavigationController.php @@ -68,7 +68,11 @@ public function show(Request $request, $nav) $site = $request->site ?? Site::selected()->handle(); if (! $nav->existsIn($site)) { - return redirect($nav->trees()->first()->showUrl()); + if ($nav->trees()->isNotEmpty()) { + return redirect($nav->trees()->first()->showUrl()); + } + + $nav->makeTree($site)->save(); } $this->authorize('view', $nav->in($site), __('You are not authorized to view navs.'));