Add user role management: introduce UserRole enum for role definitions, implement role-based access control in various resources and pages, and enhance authorization logic in the PanelProvider for improved security and user experience.
This commit is contained in:
@@ -13,6 +13,7 @@ use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class AuthorResource extends Resource
|
||||
{
|
||||
@@ -91,4 +92,34 @@ class AuthorResource extends Resource
|
||||
'edit' => Pages\EditAuthor::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return auth()->user()->can('view-authors');
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return auth()->user()->can('view-authors');
|
||||
}
|
||||
|
||||
public static function canEdit(mixed $record): bool
|
||||
{
|
||||
return auth()->user()->can('view-authors');
|
||||
}
|
||||
|
||||
public static function canDelete(mixed $record): bool
|
||||
{
|
||||
return auth()->user()->can('view-authors');
|
||||
}
|
||||
|
||||
public static function canDeleteAny(): bool
|
||||
{
|
||||
return auth()->user()->can('view-authors');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->withoutGlobalScopes();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user