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:
@@ -17,6 +17,8 @@ use Filament\Tables;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class NewsResource extends Resource
|
||||
{
|
||||
@@ -123,4 +125,34 @@ class NewsResource extends Resource
|
||||
'edit' => Pages\EditNews::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return auth()->user()->can('manage-news-and-success');
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return auth()->user()->can('manage-news-and-success');
|
||||
}
|
||||
|
||||
public static function canEdit(mixed $record): bool
|
||||
{
|
||||
return auth()->user()->can('manage-news-and-success');
|
||||
}
|
||||
|
||||
public static function canDelete(mixed $record): bool
|
||||
{
|
||||
return auth()->user()->can('manage-news-and-success');
|
||||
}
|
||||
|
||||
public static function canDeleteAny(): bool
|
||||
{
|
||||
return auth()->user()->can('manage-news-and-success');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->withoutGlobalScopes();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user