Skip to content

Commit

Permalink
Configure Jetstream classes in providers and separate panels into Adm…
Browse files Browse the repository at this point in the history
…in and App
  • Loading branch information
curtisdelicata committed Jun 28, 2024
1 parent 03c635a commit f453eb5
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 35 deletions.
104 changes: 99 additions & 5 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

namespace App\Providers\Filament;

use App\Filament\Admin\Pages;
use App\Filament\Admin\Pages\EditProfile;
use App\Http\Middleware\TeamsPermission;
use App\Listeners\CreatePersonalTeam;
use App\Listeners\SwitchTeam;
use App\Models\Team;
use Filament\Events\Auth\Registered;
use Filament\Events\TenantSet;
use Filament\Facades\Filament;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Navigation\MenuItem;
use Filament\Pages as FilamentPage;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
Expand All @@ -16,24 +26,45 @@
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Event;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\RegisteredUserController;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Jetstream;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
$panel
->default()
->id('admin')
->path('admin')
->login([AuthenticatedSessionController::class, 'create'])
->registration([RegisteredUserController::class, 'create'])
->passwordReset()
->emailVerification()
->viteTheme('resources/css/Filament/Admin/theme.css')
->colors([
'primary' => Color::Amber,
'primary' => Color::Gray,
])
->userMenuItems([
MenuItem::make()
->label('Profile')
->icon('heroicon-o-user-circle')
->url(fn () => $this->shouldRegisterMenuItem()
? url(EditProfile::getUrl())
: url($panel->getPath())),
])
->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\\Filament\\Admin\\Resources')
->discoverPages(in: app_path('Filament/Admin/Pages'), for: 'App\\Filament\\Admin\\Pages')
->pages([
Pages\Dashboard::class,
FilamentPage\Dashboard::class,
Pages\EditProfile::class,
])
->discoverWidgets(in: app_path('Filament/Admin/Widgets'), for: 'App\\Filament\\Admin\\Widgets')
->discoverWidgets(in: app_path('Filament/Admin/Widgets/Home'), for: 'App\\Filament\\Admin\\Widgets\\Home')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
Expand All @@ -51,9 +82,72 @@ public function panel(Panel $panel): Panel
])
->authMiddleware([
Authenticate::class,
TeamsPermission::class,
])
->plugins([
\BezhanSalleh\FilamentShield\FilamentShieldPlugin::make()
]);

if (Features::hasApiFeatures()) {
$panel->userMenuItems([
MenuItem::make()
->label('API Tokens')
->icon('heroicon-o-key')
->url(fn () => $this->shouldRegisterMenuItem()
? url(Pages\ApiTokenManagerPage::getUrl())
: url($panel->getPath())),
]);
}

if (Features::hasTeamFeatures()) {
$panel
->tenant(Team::class, ownershipRelationship: 'team')
->tenantRegistration(Pages\CreateTeam::class)
->tenantProfile(Pages\EditTeam::class)
->userMenuItems([
MenuItem::make()
->label('Team Settings')
->icon('heroicon-o-cog-6-tooth')
->url(fn () => $this->shouldRegisterMenuItem()
? url(Pages\EditTeam::getUrl())
: url($panel->getPath())),
]);
}

return $panel;
}

public function boot()
{
/**
* Disable Fortify routes.
*/
Fortify::$registersRoutes = false;

/**
* Disable Jetstream routes.
*/
Jetstream::$registersRoutes = false;

/**
* Listen and create personal team for new accounts.
*/
Event::listen(
Registered::class,
CreatePersonalTeam::class,
);

/**
* Listen and switch team if tenant was changed.
*/
Event::listen(
TenantSet::class,
SwitchTeam::class,
);
}

public function shouldRegisterMenuItem(): bool
{
return true; //auth()->user()?->hasVerifiedEmail() && Filament::hasTenancy() && Filament::getTenant();
}
}
61 changes: 31 additions & 30 deletions app/Providers/Filament/AppPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace App\Providers\Filament;

use App\Filament\Pages\ApiTokens;
use App\Filament\Pages\CreateTeam;
use App\Filament\Pages\EditProfile;
use App\Filament\Pages\EditTeam;
use App\Filament\App\Pages;
use App\Filament\App\Pages\EditProfile;
use App\Http\Middleware\TeamsPermission;
use App\Listeners\CreatePersonalTeam;
use App\Listeners\SwitchTeam;
use App\Models\Team;
Expand All @@ -16,7 +15,7 @@
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Navigation\MenuItem;
use Filament\Pages;
use Filament\Pages as FilamentPage;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
Expand All @@ -30,22 +29,24 @@
use Illuminate\Support\Facades\Event;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\RegisteredUserController;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Jetstream;

class AppPanelProvider extends PanelProvider
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$panel
->default()
->id('app')
->path('app')
->login()
->registration()
->login([AuthenticatedSessionController::class, 'create'])
->registration([RegisteredUserController::class, 'create'])
->passwordReset()
->emailVerification()
->viteTheme('resources/css/app.css')
->viteTheme('resources/css/Filament/App/admin/theme.css')
->colors([
'primary' => Color::Gray,
])
Expand All @@ -57,14 +58,13 @@ public function panel(Panel $panel): Panel
? url(EditProfile::getUrl())
: url($panel->getPath())),
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->discoverResources(in: app_path('Filament/App/Resources'), for: 'App\\Filament\\App\\Resources')
->discoverPages(in: app_path('Filament/App/Pages'), for: 'App\\Filament\\App\\Pages')
->pages([
Pages\Dashboard::class,
EditProfile::class,
ApiTokens::class,
FilamentPage\Dashboard::class,
Pages\EditProfile::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->discoverWidgets(in: app_path('Filament/App/Widgets/Home'), for: 'App\\Filament\\App\\Widgets\\Home')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
Expand All @@ -82,35 +82,36 @@ public function panel(Panel $panel): Panel
])
->authMiddleware([
Authenticate::class,
]);
TeamsPermission::class,
])
->plugins([
\BezhanSalleh\FilamentShield\FilamentShieldPlugin::make()
]);

if (Features::hasApiFeatures()) {
$panel->userMenuItems([
MenuItem::make()
->label('API Tokens')
->icon('heroicon-o-key')
->url(fn () => $this->shouldRegisterMenuItem()
? url(ApiTokens::getUrl())
? url(Pages\ApiTokenManagerPage::getUrl())
: url($panel->getPath())),
]);
}

if (Features::hasTeamFeatures()) {
$panel
->tenant(Team::class)
->tenantRegistration(CreateTeam::class)
->tenantProfile(EditTeam::class)
->tenant(Team::class, ownershipRelationship: 'team')
->tenantRegistration(Pages\CreateTeam::class)
->tenantProfile(Pages\EditTeam::class)
->userMenuItems([
MenuItem::make()
->label('Team Settings')
->icon('heroicon-o-cog-6-tooth')
->url(fn () => $this->shouldRegisterMenuItem()
? url(EditTeam::getUrl())
? url(Pages\EditTeam::getUrl())
: url($panel->getPath())),
])
->plugins([
\BezhanSalleh\FilamentShield\FilamentShieldPlugin::make()
]);
]);
}

return $panel;
Expand All @@ -119,25 +120,25 @@ public function panel(Panel $panel): Panel
public function boot()
{
/**
* Disable Fortify routes
* Disable Fortify routes.
*/
Fortify::$registersRoutes = false;

/**
* Disable Jetstream routes
* Disable Jetstream routes.
*/
Jetstream::$registersRoutes = false;

/**
* Listen and create personal team for new accounts
* Listen and create personal team for new accounts.
*/
Event::listen(
Registered::class,
CreatePersonalTeam::class,
);

/**
* Listen and switch team if tenant was changed
* Listen and switch team if tenant was changed.
*/
Event::listen(
TenantSet::class,
Expand All @@ -147,6 +148,6 @@ public function boot()

public function shouldRegisterMenuItem(): bool
{
return auth()->user()?->hasVerifiedEmail() && Filament::hasTenancy() && Filament::getTenant();
return true; //auth()->user()?->hasVerifiedEmail() && Filament::hasTenancy() && Filament::getTenant();
}
}

0 comments on commit f453eb5

Please sign in to comment.