panelId = 'dash'; $this->loadConfiguration(); $panel = $panel ->default($this->panelDefault) ->id($this->panelId) ->path($this->panelPath) ->colors($this->panelColor) ->brandName($this->panelBrandName) ->font($this->panelFont) ->favicon(asset($this->panelFavicon)) ->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources') ->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages') ->pages([ Dashboard::class, ]) ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets') ->widgets([ AccountWidget::class, FilamentInfoWidget::class, ]) ->middleware([ EncryptCookies::class, AddQueuedCookiesToResponse::class, StartSession::class, AuthenticateSession::class, ShareErrorsFromSession::class, VerifyCsrfToken::class, SubstituteBindings::class, DisableBladeIconComponents::class, DispatchServingFilamentEvent::class, ]) ->authMiddleware([ Authenticate::class, ]) ->plugins([ FilamentLoggerPlugin::make(), FilamentLogViewerPlugin::make(), FilamentMailsPlugin::make()->canManageMails(function (): bool { $user = Auth::user(); return $user->hasRole('admin') || $user->hasPermissionTo('manage mails'); }), ]) ->routes(fn() => FilamentMails::routes()); $this->applyConditionalConfiguration($panel); return $panel; } private function loadConfiguration(): void { try { $this->panelConfig = DbConfig::getGroup('panel'); } catch (\Exception $e) { Log::error($e->getMessage()); $this->panelConfig = []; } // Load basic panel configuration $this->panelDefault = $this->getConfig('panel_default') === $this->panelId; $this->panelPath = $this->getConfig("panel_route_{$this->panelId}", $this->panelId); $this->panelBrandName = $this->getConfig("panel_name_{$this->panelId}", config('app.name')); $this->panelFont = $this->getConfig("panel_font_{$this->panelId}", 'Poppins'); $this->panelColor = ColorHelper::getPanelColor($this->panelId); // Load feature flags $this->panelLogin = $this->getConfig("panel_enable_login_{$this->panelId}", true); $this->panelRegistration = $this->getConfig("panel_enable_registration_{$this->panelId}", false); $this->panelProfile = $this->getConfig("panel_enable_profile_{$this->panelId}", false); // Load SPA configuration $this->panelSPA = $this->getConfig("panel_spa_{$this->panelId}", false); $this->panelSPAPrefetch = $this->getConfig("panel_spa_prefetch_{$this->panelId}", false); $this->panelSPAExceptions = $this->getConfig("panel_spa_exceptions_{$this->panelId}", []); // Load branding configuration $this->panelBrandLogoShow = $this->getConfig("panel_show_logo_{$this->panelId}") === 'show'; $this->panelBrandLogoLight = $this->getConfig("panel_logo_light_{$this->panelId}", 'favicon.svg'); $this->panelBrandLogoDark = $this->getConfig("panel_logo_dark_{$this->panelId}", 'favicon.svg'); $this->panelBrandLogoHeight = $this->getConfig("panel_logo_height_{$this->panelId}"); $this->panelFavicon = $this->getConfig("panel_favicon_{$this->panelId}", 'favicon.svg'); // Load MFA configuration $this->panelMFA = $this->getConfig("panel_enable_mfa_{$this->panelId}", false); $this->panelMFAType = $this->getConfig("panel_mfa_type_{$this->panelId}", 'app'); $this->panelMFABrandName = $this->getConfig("panel_mfa_app_brand_name_{$this->panelId}", config('app.name')); $this->panelMFARecoverable = $this->getConfig("panel_mfa_app_recoverable_{$this->panelId}", false); $this->panelMFARecoveryCodeRegenerate = $this->getConfig("panel_mfa_app_recovery_code_regeneratable_{$this->panelId}", false); $this->panelMFACodeWindow = $this->getConfig("panel_mfa_app_code_window_{$this->panelId}", 4); $this->panelMFARecoveryCodeCount = $this->getConfig("panel_mfa_app_recovery_code_count_{$this->panelId}", 8); $this->panelMFAEmailCodeExpiry = $this->getConfig("panel_mfa_email_code_expiry_{$this->panelId}", 2); $this->panelMFARequired = $this->getConfig("panel_mfa_is_required_{$this->panelId}") === 'yes'; } private function applyConditionalConfiguration(Panel $panel): void { $actions = [ 'login' => [$this->panelLogin, fn() => $panel->login()], 'register' => [$this->panelRegistration, fn() => $panel->registration()], 'profile' => [$this->panelProfile, fn() => $panel->profile()], 'spa' => [$this->panelSPA, fn() => $panel ->spa(hasPrefetching: $this->panelSPAPrefetch) ->spaUrlExceptions(exceptions: $this->panelSPAExceptions) ], 'logo' => [$this->panelBrandLogoShow, fn() => $panel ->brandLogo(asset($this->panelBrandLogoLight)) ->darkModeBrandLogo(asset($this->panelBrandLogoDark)) ->brandLogoHeight($this->panelBrandLogoHeight) ], ]; foreach ($actions as [$condition, $callback]) { $condition && $callback(); } $this->configureMFA($panel); } private function getConfig(string $key, $default = null) { return ArrayHelper::getValueFromArray($key, $this->panelConfig) ?? $default; } private function configureMFA(Panel $panel): void { if (!$this->panelMFA) { return; } $authentication = $this->panelMFAType === 'app' ? AppAuthentication::make() ->brandName($this->panelMFABrandName) ->recoverable($this->panelMFARecoverable) ->recoveryCodeCount($this->panelMFARecoveryCodeCount) ->regenerableRecoveryCodes($this->panelMFARecoveryCodeRegenerate) ->codeWindow($this->panelMFACodeWindow) : EmailAuthentication::make() ->codeExpiryMinutes($this->panelMFAEmailCodeExpiry); $panel->multiFactorAuthentication([$authentication], isRequired: $this->panelMFARequired); } }