From 34cb4d2e847f22c41361b19e5a879bceaeccbab3 Mon Sep 17 00:00:00 2001 From: Duncan McClean <19637309+duncanmcclean@users.noreply.github.com> Date: Thu, 14 Dec 2023 16:25:08 +0000 Subject: [PATCH] [4.x] Create tree for navigation if one doesn't exist (#9032) 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.'));