From 2f0178481d8ec38b9a519b83a8da1405cab46f12 Mon Sep 17 00:00:00 2001 From: MatthewBiskas <64212185+thethunderturner@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:31:30 +0200 Subject: [PATCH] Fix duplication for Octane (#51) * Update SetTheme.php Fixes Octane duplication issue * Update SetTheme.php Better approach! Dont even add if its already there --- src/Http/Middleware/SetTheme.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Http/Middleware/SetTheme.php b/src/Http/Middleware/SetTheme.php index 099a103..3cffea2 100644 --- a/src/Http/Middleware/SetTheme.php +++ b/src/Http/Middleware/SetTheme.php @@ -33,15 +33,24 @@ public function handle(Request $request, Closure $next): Response return $next($request); } - $panel->userMenuItems( - ThemesPlugin::canView() ? - [ - MenuItem::make('Themes') - ->label(__('themes::themes.themes')) - ->icon(config('themes.icon')) - ->url(ThemesPage::getUrl()), - ] : [] - ); + /** + * Important for Laravel Octane! + * + * Check if item already exists before adding it + * to the menu items. + */ + if(!isset($panel->getUserMenuItems()[__('themes::themes.themes')])){ + $panel->userMenuItems( + ThemesPlugin::canView() ? + [ + __('themes::themes.themes') => + MenuItem::make('Themes') + ->label(__('themes::themes.themes')) + ->icon(config('themes.icon')) + ->url(ThemesPage::getUrl()), + ] : [] + ); + } FilamentColor::register($themes->getCurrentThemeColor());