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 11b5a4f commit 1ec5426
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 8 deletions.
File renamed without changes.
Empty file.
Empty file.
Empty file.
105 changes: 97 additions & 8 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,29 +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()
->registration()
->login([AuthenticatedSessionController::class, 'create'])
->registration([RegisteredUserController::class, 'create'])
->passwordReset()
->emailVerification()
->profile()
->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 @@ -56,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();
}
}
153 changes: 153 additions & 0 deletions app/Providers/Filament/AppPanelProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

namespace App\Providers\Filament;

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;
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\Navigation\MenuItem;
use Filament\Pages as FilamentPage;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
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
{
$panel
->default()
->id('app')
->path('app')
->login([AuthenticatedSessionController::class, 'create'])
->registration([RegisteredUserController::class, 'create'])
->passwordReset()
->emailVerification()
->viteTheme('resources/css/Filament/App/admin/theme.css')
->colors([
'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/App/Resources'), for: 'App\\Filament\\App\\Resources')
->discoverPages(in: app_path('Filament/App/Pages'), for: 'App\\Filament\\App\\Pages')
->pages([
FilamentPage\Dashboard::class,
Pages\EditProfile::class,
])
->discoverWidgets(in: app_path('Filament/App/Widgets/Home'), for: 'App\\Filament\\App\\Widgets\\Home')
->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,
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();
}
}

0 comments on commit 1ec5426

Please sign in to comment.