diff --git a/routes/web.php b/routes/web.php index 5963648..82ae848 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,4 +5,4 @@ Route::get('/impersonate/stop', fn () => ImpersonateLink::leave()) ->name('filament-authentication.stop.impersonation') - ->middleware(config('filament-authentication.impersonate.guard')); + ->middleware('web'); diff --git a/src/Actions/ImpersonateLink.php b/src/Actions/ImpersonateLink.php index 675db97..be4e44a 100644 --- a/src/Actions/ImpersonateLink.php +++ b/src/Actions/ImpersonateLink.php @@ -8,7 +8,7 @@ use Illuminate\Http\RedirectResponse; use Lab404\Impersonate\Services\ImpersonateManager; use Illuminate\Contracts\Auth\Authenticatable as User; - +use Phpsa\FilamentAuthentication\FilamentAuthentication; class ImpersonateLink { @@ -30,7 +30,8 @@ public static function make(): Action */ public static function allowed(User $current, User $target): bool { - return config('filament-authentication.impersonate.enabled', false) + $enabled = FilamentAuthentication::getPlugin()->impersonateEnabled(); + return $enabled && $current->isNot($target) && ! app(ImpersonateManager::class)->isImpersonating() && (! method_exists($current, 'canImpersonate') || $current->canImpersonate()) @@ -46,19 +47,22 @@ public static function impersonate(User $record): false|Redirector|RedirectRespo app(ImpersonateManager::class)->take( Filament::auth()->user(), $record, - config('filament-authentication.impersonate.guard', 'web') + FilamentAuthentication::getPlugin()->getImpersonateGuard() ); + session()->put('impersonate.back_to', url()->previous()); + session()->forget(array_unique([ - 'password_hash_'.config('filament-authentication.impersonate.guard', 'web'), - 'password_hash_'.config('filament.auth.guard'), + 'password_hash_' . FilamentAuthentication::getPlugin()->getImpersonateGuard(), + 'password_hash_' . config('filament.auth.guard'), ])); - return redirect(config('filament-authentication.impersonate.redirect', '/')); + return redirect(FilamentAuthentication::getPlugin()->getImpersonateRedirect()); } public static function leave(): Redirector|RedirectResponse { + if (! app(ImpersonateManager::class)->isImpersonating()) { return redirect('/'); } @@ -66,12 +70,12 @@ public static function leave(): Redirector|RedirectResponse app(ImpersonateManager::class)->leave(); session()->forget(array_unique([ - 'password_hash_'.config('filament-authentication.impersonate.guard'), - 'password_hash_'.config('filament.auth.guard'), + 'password_hash_' . FilamentAuthentication::getPlugin()->getImpersonateGuard(), + 'password_hash_' . config('filament.auth.guard'), ])); return redirect( - session()->pull('impersonate.back_to') ?? config('filament.path') + session()->pull('impersonate.back_to') ?? '/' ); } } diff --git a/src/FilamentAuthentication.php b/src/FilamentAuthentication.php index 555753d..4f4dc45 100644 --- a/src/FilamentAuthentication.php +++ b/src/FilamentAuthentication.php @@ -2,16 +2,146 @@ namespace Phpsa\FilamentAuthentication; -use Filament\Navigation\MenuItem; +use Closure; use Filament\Panel; +use App\Models\User; +use Filament\Contracts\Plugin; +use Spatie\Permission\Models\Role; +use Filament\Tables\Columns\TextColumn; +use Spatie\Permission\Models\Permission; +use Phpsa\FilamentAuthentication\Resources\RoleResource; +use Phpsa\FilamentAuthentication\Resources\UserResource; +use Phpsa\FilamentAuthentication\Resources\PermissionResource; +use Phpsa\FilamentAuthentication\Http\Middleware\ImpersonatingMiddleware; -class FilamentAuthentication +class FilamentAuthentication implements Plugin { - public static function resources(array $with = []): array + protected bool $preloadRoles = true; + protected bool $preloadPermissions = true; + protected bool $impersonate = false; + protected string $impersonateGuard = 'web'; + protected string|Closure $impersonateRedirect = '/'; + + /** + * @var array + */ + protected array $models = [ + 'User' => User::class, + 'Role' => Role::class, + 'Permission' => Permission::class, + ]; + + /** + * @var array + */ + protected array $resources = [ + 'UserResource' => UserResource::class, + 'RoleResource' => RoleResource::class, + 'PermissionResource' => PermissionResource::class, + ]; + + public static function make(): self + { + return new static(); + } + + public static function getPlugin(): self + { + return filament('filament-authentication'); + } + + public function getId(): string + { + return 'filament-authentication'; + } + + public function register(Panel $panel): void + { + $panel->resources($this->resources); + $panel->middleware([ImpersonatingMiddleware::class]); + } + + public function boot(Panel $panel): void + { + TextColumn::macro('humanDate', function () { + /** @var \Filament\Tables\Columns\TextColumn&\Filament\Tables\Columns\Concerns\CanFormatState $this */ + $this->formatStateUsing(fn ($state): ?string => $state ? $state->diffForHumans() : null); + + return $this; + }); + } + + public function setPreload(bool $roles = true, bool $permissions = true): self + { + $this->preloadRoles = $roles; + $this->preloadPermissions = $permissions; + + return $this; + } + + public function getPreloadRoles(): bool + { + return $this->preloadRoles; + } + + public function getPreloadPermissions(): bool + { + return $this->preloadPermissions; + } + + public function setImpersonation(bool $enabled = true, string $guard = 'web', string|Closure $redirect = '/'): self + { + $this->impersonate = $enabled; + $this->impersonateGuard = $guard; + $this->impersonateRedirect = $redirect; + + return $this; + } + + public function impersonateEnabled(): bool + { + return $this->impersonate; + } + + public function getImpersonateGuard(): string + { + return $this->impersonateGuard; + } + + public function getImpersonateRedirect(): string|Closure + { + $value = $this->impersonateRedirect; + if (! $value instanceof Closure) { + return $value; + } + return $value(); + } + + /** + * @param array $overrides + */ + public function overrideModels(array $overrides): self + { + $this->models = array_merge($this->models, $overrides); + return $this; + } + + public function getModel(string $model): string + { + return $this->models[$model]; + } + + /** + * @param array $overrides + */ + public function overrideResources(array $overrides): self + { + $this->resources = array_merge($this->resources, $overrides); + return $this; + } + + public function getResource(string $resource): string { - return array_merge( - config('filament-authentication.resources'), - $with - ); + return $this->resources[$resource]; } } diff --git a/src/FilamentAuthenticationProvider.php b/src/FilamentAuthenticationProvider.php index 6cf1155..b87b57f 100644 --- a/src/FilamentAuthenticationProvider.php +++ b/src/FilamentAuthenticationProvider.php @@ -15,44 +15,12 @@ class FilamentAuthenticationProvider extends PackageServiceProvider { public static string $name = 'filament-authentication'; - protected array $widgets = [ - LatestUsersWidget::class, - ]; - - protected function getResources(): array - { - return config('filament-authentication.resources'); - } - - protected function getWidgets(): array - { - return config('filament-authentication.resources.widgets'); - } public function configurePackage(Package $package): void { - Config::push('filament.middleware.base', ImpersonatingMiddleware::class); - $package->name('filament-authentication') - ->hasConfigFile() ->hasViews() ->hasRoute('web') ->hasTranslations(); } - - public function getPages(): array - { - return config('filament-authentication.pages'); - } - - public function packageRegistered(): void - { - - TextColumn::macro('humanDate', function () { - /** @var \Filament\Tables\Columns\TextColumn&\Filament\Tables\Columns\Concerns\CanFormatState $this */ - $this->formatStateUsing(fn ($state): ?string => $state ? $state->diffForHumans() : null); - - return $this; - }); - } } diff --git a/src/Http/Middleware/ImpersonatingMiddleware.php b/src/Http/Middleware/ImpersonatingMiddleware.php index a3212c5..ac8637f 100644 --- a/src/Http/Middleware/ImpersonatingMiddleware.php +++ b/src/Http/Middleware/ImpersonatingMiddleware.php @@ -24,7 +24,7 @@ public function handle(Request $request, \Closure $next) $response->setContent( str_replace( '', - $this->getHtmlContent($request).'', + $this->getHtmlContent($request) . '', // @phpstan-ignore-next-line $response->getContent() ) diff --git a/src/Resources/PermissionResource.php b/src/Resources/PermissionResource.php index 61e5d62..fd1b227 100644 --- a/src/Resources/PermissionResource.php +++ b/src/Resources/PermissionResource.php @@ -15,6 +15,7 @@ use Filament\Tables\Actions\DeleteBulkAction; use Filament\Forms\Components\Section as Card; use Filament\Forms\Components\BelongsToManyMultiSelect; +use Phpsa\FilamentAuthentication\FilamentAuthentication; use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\EditPermission; use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\ViewPermission; use Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages\ListPermissions; @@ -29,7 +30,7 @@ class PermissionResource extends Resource public function __construct() { - static::$model = config('filament-authentication.models.Permission'); + static::$model = FilamentAuthentication::getPlugin()->getModel('Permission'); } public static function getLabel(): string @@ -61,10 +62,7 @@ public static function form(Form $form): Form ->required() ->label(strval(__('filament-authentication::filament-authentication.field.guard_name'))) ->default(config('auth.defaults.guard')), - // BelongsToManyMultiSelect::make('roles') - // ->label(strval(__('filament-authentication::filament-authentication.field.roles'))) - // ->relationship('roles', 'name') - // ->preload(config('filament-spatie-roles-permissions.preload_roles')) + ]), ]), ]); diff --git a/src/Resources/PermissionResource/Pages/CreatePermission.php b/src/Resources/PermissionResource/Pages/CreatePermission.php index fbb01b6..f3d5d71 100644 --- a/src/Resources/PermissionResource/Pages/CreatePermission.php +++ b/src/Resources/PermissionResource/Pages/CreatePermission.php @@ -2,16 +2,17 @@ namespace Phpsa\FilamentAuthentication\Resources\PermissionResource\Pages; -use Filament\Resources\Pages\CreateRecord; use Illuminate\Support\Facades\Config; -use Spatie\Permission\Contracts\Permission; +use Filament\Resources\Pages\CreateRecord; use Spatie\Permission\PermissionRegistrar; +use Spatie\Permission\Contracts\Permission; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class CreatePermission extends CreateRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.PermissionResource'); + return FilamentAuthentication::getPlugin()->getResource('PermissionResource'); } public function afterSave(): void diff --git a/src/Resources/PermissionResource/Pages/EditPermission.php b/src/Resources/PermissionResource/Pages/EditPermission.php index 6528428..822961b 100644 --- a/src/Resources/PermissionResource/Pages/EditPermission.php +++ b/src/Resources/PermissionResource/Pages/EditPermission.php @@ -8,12 +8,13 @@ use Filament\Resources\Pages\EditRecord; use Spatie\Permission\PermissionRegistrar; use Spatie\Permission\Contracts\Permission; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class EditPermission extends EditRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.PermissionResource'); + return FilamentAuthentication::getPlugin()->getResource('PermissionResource'); } public function afterSave(): void diff --git a/src/Resources/PermissionResource/Pages/ListPermissions.php b/src/Resources/PermissionResource/Pages/ListPermissions.php index e884e96..d078783 100644 --- a/src/Resources/PermissionResource/Pages/ListPermissions.php +++ b/src/Resources/PermissionResource/Pages/ListPermissions.php @@ -8,12 +8,13 @@ use Filament\Tables\Actions\BulkAction; use Filament\Resources\Pages\ListRecords; use Illuminate\Database\Eloquent\Collection; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class ListPermissions extends ListRecords { public static function getResource(): string { - return Config::get('filament-authentication.resources.PermissionResource'); + return FilamentAuthentication::getPlugin()->getResource('PermissionResource'); } protected function getHeaderActions(): array diff --git a/src/Resources/PermissionResource/Pages/ViewPermission.php b/src/Resources/PermissionResource/Pages/ViewPermission.php index 10592d9..b9b414a 100644 --- a/src/Resources/PermissionResource/Pages/ViewPermission.php +++ b/src/Resources/PermissionResource/Pages/ViewPermission.php @@ -5,12 +5,13 @@ use Filament\Actions\EditAction; use Illuminate\Support\Facades\Config; use Filament\Resources\Pages\ViewRecord; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class ViewPermission extends ViewRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.PermissionResource'); + return FilamentAuthentication::getPlugin()->getResource('PermissionResource'); } protected function getHeaderActions(): array diff --git a/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php b/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php index 604a27c..dd532b0 100644 --- a/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php +++ b/src/Resources/PermissionResource/RelationManager/RoleRelationManager.php @@ -12,6 +12,7 @@ use Spatie\Permission\PermissionRegistrar; use Filament\Tables\Actions\DissociateBulkAction; use Filament\Resources\RelationManagers\RelationManager; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class RoleRelationManager extends RelationManager { @@ -44,7 +45,7 @@ public function table(Table $table): Table ]) ->headerActions([ CreateAction::make(), - AttachAction::make()->preloadRecordSelect(config('filament-authentication.preload_roles', true)) + AttachAction::make()->preloadRecordSelect(FilamentAuthentication::getPlugin()->getPreloadRoles()) ->recordSelect(fn($select) => $select->multiple()) ->closeModalByClickingAway(false), ]) diff --git a/src/Resources/RoleResource.php b/src/Resources/RoleResource.php index 0c40b63..0f6bbf6 100644 --- a/src/Resources/RoleResource.php +++ b/src/Resources/RoleResource.php @@ -15,6 +15,7 @@ use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Actions\DeleteBulkAction; use Filament\Forms\Components\Section as Card; +use Phpsa\FilamentAuthentication\FilamentAuthentication; use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\EditRole; use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ViewRole; use Phpsa\FilamentAuthentication\Resources\RoleResource\Pages\ListRoles; @@ -30,7 +31,7 @@ class RoleResource extends Resource public function __construct() { - static::$model = config('filament-authentication.models.Role'); + static::$model = FilamentAuthentication::getPlugin()->getModel('Role'); } public static function getLabel(): string @@ -63,11 +64,7 @@ public static function form(Form $form): Form ->label(strval(__('filament-authentication::filament-authentication.field.guard_name'))) ->required() ->default(config('auth.defaults.guard')), - // BelongsToManyMultiSelect::make('permissions') - // ->label(strval(__('filament-authentication::filament-authentication.field.permissions'))) - // ->relationship('permissions', 'name') - // ->hidden() - // ->preload(config('filament-spatie-roles-permissions.preload_permissions')) + ]), ]), ]); diff --git a/src/Resources/RoleResource/Pages/CreateRole.php b/src/Resources/RoleResource/Pages/CreateRole.php index 3c0095c..b24d8c7 100644 --- a/src/Resources/RoleResource/Pages/CreateRole.php +++ b/src/Resources/RoleResource/Pages/CreateRole.php @@ -2,16 +2,17 @@ namespace Phpsa\FilamentAuthentication\Resources\RoleResource\Pages; -use Filament\Resources\Pages\CreateRecord; -use Illuminate\Support\Facades\Config; use Spatie\Permission\Contracts\Role; +use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\CreateRecord; use Spatie\Permission\PermissionRegistrar; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class CreateRole extends CreateRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.RoleResource'); + return FilamentAuthentication::getPlugin()->getResource('RoleResource'); } public function afterSave(): void diff --git a/src/Resources/RoleResource/Pages/EditRole.php b/src/Resources/RoleResource/Pages/EditRole.php index be32701..08ab7bf 100644 --- a/src/Resources/RoleResource/Pages/EditRole.php +++ b/src/Resources/RoleResource/Pages/EditRole.php @@ -8,12 +8,13 @@ use Illuminate\Support\Facades\Config; use Filament\Resources\Pages\EditRecord; use Spatie\Permission\PermissionRegistrar; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class EditRole extends EditRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.RoleResource'); + return FilamentAuthentication::getPlugin()->getResource('RoleResource'); } public function afterSave(): void diff --git a/src/Resources/RoleResource/Pages/ListRoles.php b/src/Resources/RoleResource/Pages/ListRoles.php index 1eb3e8b..7bb6029 100644 --- a/src/Resources/RoleResource/Pages/ListRoles.php +++ b/src/Resources/RoleResource/Pages/ListRoles.php @@ -5,12 +5,13 @@ use Filament\Actions\CreateAction; use Illuminate\Support\Facades\Config; use Filament\Resources\Pages\ListRecords; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class ListRoles extends ListRecords { public static function getResource(): string { - return Config::get('filament-authentication.resources.RoleResource'); + return FilamentAuthentication::getPlugin()->getResource('RoleResource'); } protected function getHeaderActions(): array diff --git a/src/Resources/RoleResource/Pages/ViewRole.php b/src/Resources/RoleResource/Pages/ViewRole.php index 09411d2..9549556 100644 --- a/src/Resources/RoleResource/Pages/ViewRole.php +++ b/src/Resources/RoleResource/Pages/ViewRole.php @@ -5,12 +5,13 @@ use Filament\Actions\EditAction; use Illuminate\Support\Facades\Config; use Filament\Resources\Pages\ViewRecord; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class ViewRole extends ViewRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.RoleResource'); + return FilamentAuthentication::getPlugin()->getResource('RoleResource'); } protected function getHeaderActions(): array diff --git a/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php b/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php index 3ca0b45..6a468d7 100644 --- a/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php +++ b/src/Resources/RoleResource/RelationManager/PermissionRelationManager.php @@ -7,11 +7,12 @@ use Filament\Tables\Columns\TextColumn; use Filament\Forms\Components\TextInput; use Filament\Tables\Actions\AttachAction; +use Filament\Tables\Actions\CreateAction; use Filament\Tables\Actions\DetachAction; use Spatie\Permission\PermissionRegistrar; -use Filament\Resources\RelationManagers\RelationManager; -use Filament\Tables\Actions\CreateAction; use Filament\Tables\Actions\DetachBulkAction; +use Filament\Resources\RelationManagers\RelationManager; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class PermissionRelationManager extends RelationManager { @@ -48,7 +49,7 @@ public function table(Table $table): Table ->headerActions([ CreateAction::make(), AttachAction::make() - ->preloadRecordSelect(config('filament-authentication.preload_permissions', true)) + ->preloadRecordSelect(FilamentAuthentication::getPlugin()->getPreloadPermissions()) ->recordSelect(fn($select) => $select->multiple()) ->closeModalByClickingAway(false), ]) diff --git a/src/Resources/UserResource.php b/src/Resources/UserResource.php index 896d06a..3162ea7 100644 --- a/src/Resources/UserResource.php +++ b/src/Resources/UserResource.php @@ -17,6 +17,7 @@ use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Actions\DeleteBulkAction; use Filament\Forms\Components\Section as Card; +use Phpsa\FilamentAuthentication\FilamentAuthentication; use Phpsa\FilamentAuthentication\Actions\ImpersonateLink; use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\EditUser; use Phpsa\FilamentAuthentication\Resources\UserResource\Pages\ViewUser; @@ -31,7 +32,7 @@ class UserResource extends Resource public function __construct() { - static::$model = config('filament-authentication.models.User'); + static::$model = FilamentAuthentication::getPlugin()->getModel('User'); } public static function getNavigationGroup(): ?string @@ -78,7 +79,7 @@ public static function form(Form $form): Form Select::make('roles') ->multiple() ->relationship('roles', 'name') - ->preload(config('filament-authentication.preload_roles')) + ->preload(FilamentAuthentication::getPlugin()->getPreloadRoles()) ->label(strval(__('filament-authentication::filament-authentication.field.user.roles'))), ])->columns(2), ]); diff --git a/src/Resources/UserResource/Pages/CreateUser.php b/src/Resources/UserResource/Pages/CreateUser.php index 7777f3a..68eaa47 100644 --- a/src/Resources/UserResource/Pages/CreateUser.php +++ b/src/Resources/UserResource/Pages/CreateUser.php @@ -2,16 +2,17 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages; -use Filament\Resources\Pages\CreateRecord; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\CreateRecord; use Phpsa\FilamentAuthentication\Events\UserCreated; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class CreateUser extends CreateRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.UserResource'); + return FilamentAuthentication::getPlugin()->getResource('UserResource'); } protected function afterCreate(): void diff --git a/src/Resources/UserResource/Pages/EditUser.php b/src/Resources/UserResource/Pages/EditUser.php index 5d5e571..83cba75 100644 --- a/src/Resources/UserResource/Pages/EditUser.php +++ b/src/Resources/UserResource/Pages/EditUser.php @@ -2,18 +2,19 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages; -use Filament\Actions\DeleteAction; use Filament\Actions\ViewAction; +use Filament\Actions\DeleteAction; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Config; use Filament\Resources\Pages\EditRecord; use Phpsa\FilamentAuthentication\Events\UserUpdated; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class EditUser extends EditRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.UserResource'); + return FilamentAuthentication::getPlugin()->getResource('UserResource'); } protected function mutateFormDataBeforeSave(array $data): array diff --git a/src/Resources/UserResource/Pages/ListUsers.php b/src/Resources/UserResource/Pages/ListUsers.php index 6e0d44e..e61f930 100644 --- a/src/Resources/UserResource/Pages/ListUsers.php +++ b/src/Resources/UserResource/Pages/ListUsers.php @@ -5,12 +5,13 @@ use Filament\Actions\CreateAction; use Illuminate\Support\Facades\Config; use Filament\Resources\Pages\ListRecords; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class ListUsers extends ListRecords { public static function getResource(): string { - return Config::get('filament-authentication.resources.UserResource'); + return FilamentAuthentication::getPlugin()->getResource('UserResource'); } protected function getActions(): array diff --git a/src/Resources/UserResource/Pages/ViewUser.php b/src/Resources/UserResource/Pages/ViewUser.php index 73e5cd5..110d25e 100644 --- a/src/Resources/UserResource/Pages/ViewUser.php +++ b/src/Resources/UserResource/Pages/ViewUser.php @@ -2,19 +2,20 @@ namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages; -use Filament\Facades\Filament; use Filament\Actions\Action; +use Filament\Facades\Filament; use Filament\Actions\EditAction; -use Filament\Resources\Pages\ViewRecord; use Illuminate\Support\Facades\Config; +use Filament\Resources\Pages\ViewRecord; use Illuminate\Validation\UnauthorizedException; +use Phpsa\FilamentAuthentication\FilamentAuthentication; use Phpsa\FilamentAuthentication\Actions\ImpersonateLink; class ViewUser extends ViewRecord { public static function getResource(): string { - return Config::get('filament-authentication.resources.UserResource'); + return FilamentAuthentication::getPlugin()->getResource('UserResource'); } protected function getHeaderActions(): array diff --git a/src/Widgets/LatestUsersWidget.php b/src/Widgets/LatestUsersWidget.php index f8977fd..6f1232e 100644 --- a/src/Widgets/LatestUsersWidget.php +++ b/src/Widgets/LatestUsersWidget.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Config; use Filament\Tables\Columns\TextColumn; use Illuminate\Database\Eloquent\Builder; +use Phpsa\FilamentAuthentication\FilamentAuthentication; class LatestUsersWidget extends TableWidget { @@ -45,6 +46,6 @@ public static function canView(): bool public static function getResource(): string { - return Config::get('filament-authentication.resources.UserResource'); + return FilamentAuthentication::getPlugin()->getResource('UserResource'); } }