How to Move the Initial Laravel Filament Panel into a Subfolder
When you first add a panel in Laravel Filament, it generates resources and widgets in the 'filament' folder. While this works fine if you only plan on having a single panel, issues arise when you add another panel. By default, new panels are generated in a subfolder of the 'filament' folder, which can become messy and less than ideal for project organisation.
To address this, you can modify your original panel provider to ensure that the panel resources also reside in a subfolder. This adjustment helps maintain a clear and consistent folder structure. Below is the code you need to update:
class AdminPanelProvider extends PanelProvider { public function panel(Panel $panel): Panel { return $panel ->default() ->id('admin') ->path('admin') ->colors([ 'primary' => Color::<em>Amber</em>, ])- ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources') + ->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\\Filament\\Admin\\Resources') - ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages') + ->discoverPages(in: app_path('Filament/Admin/Pages'), for: 'App\\Filament\\Admin\\Pages') ->pages([ Pages\Dashboard::class, ])- ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets') + ->discoverWidgets(in: app_path('Filament/Admin/Widgets'), for: 'App\\Filament\\Admin\\Widgets') ->widgets([ Widgets\AccountWidget::class, Widgets\FilamentInfoWidget::class, ]) ->middleware([ EncryptCookies::class, AddQueuedCookiesToResponse::class, StartSession::class, AuthenticateSession::class, ShareErrorsFromSession::class, VerifyCsrfToken::class, SubstituteBindings::class, DisableBladeIconComponents::class, DispatchServingFilamentEvent::class, ]) ->authMiddleware([ Authenticate::class, ]); } }
Important Note
If you've already generated resources, widgets, or pages, you’ll need to manually move these into the newly specified subfolder. For example, any resources in `App\Filament\Resources` should now be relocated to App\Filament\Admin\Resources. Similarly, widgets and pages should be moved into their respective subfolders.
Syntax highlighting by Torchlight.