-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure Jetstream classes in providers and separate panels into Adm…
…in and App
- Loading branch information
1 parent
11b5a4f
commit 1ec5426
Showing
6 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |