- DocumentResource: 添加 document.view 权限检查 - SystemSettingResource: 添加 system-setting.view 权限检查 - ActivityLogResource: 添加 activity-log.view 权限检查 - TerminalResource: 添加 terminal.view 权限检查 - SopTemplateResource: 添加 sop-template.view 权限检查 - GroupResource: 添加 group.view 权限检查 - UserResource: 添加 user.view 权限检查 - RoleResource: 添加 role.viewAny 权限检查 所有资源都实现了 shouldRegisterNavigation() 方法 根据用户权限动态显示/隐藏导航菜单项
123 lines
3.9 KiB
PHP
123 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\GroupResource\Pages;
|
|
use App\Filament\Resources\GroupResource\RelationManagers;
|
|
use App\Models\Group;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class GroupResource extends Resource
|
|
{
|
|
protected static ?string $model = Group::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-user-group';
|
|
|
|
protected static ?string $navigationLabel = '分组管理';
|
|
|
|
protected static ?string $modelLabel = '分组';
|
|
|
|
protected static ?string $pluralModelLabel = '分组';
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
/**
|
|
* 控制导航菜单是否显示
|
|
*/
|
|
public static function shouldRegisterNavigation(): bool
|
|
{
|
|
return auth()->user()?->can('group.view') ?? false;
|
|
}
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\TextInput::make('name')
|
|
->label('分组名称')
|
|
->required()
|
|
->maxLength(255)
|
|
->placeholder('请输入分组名称'),
|
|
Forms\Components\Textarea::make('description')
|
|
->label('分组描述')
|
|
->rows(3)
|
|
->maxLength(65535)
|
|
->placeholder('请输入分组描述(可选)')
|
|
->columnSpanFull(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('ID')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('name')
|
|
->label('分组名称')
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('description')
|
|
->label('分组描述')
|
|
->limit(50)
|
|
->searchable()
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('users_count')
|
|
->label('成员数量')
|
|
->counts('users')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->label('创建时间')
|
|
->dateTime('Y-m-d H:i:s')
|
|
->sortable()
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->label('更新时间')
|
|
->dateTime('Y-m-d H:i:s')
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make()
|
|
->label('查看'),
|
|
Tables\Actions\EditAction::make()
|
|
->label('编辑'),
|
|
Tables\Actions\DeleteAction::make()
|
|
->label('删除'),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make()
|
|
->label('批量删除'),
|
|
]),
|
|
])
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\UsersRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListGroups::route('/'),
|
|
'create' => Pages\CreateGroup::route('/create'),
|
|
'edit' => Pages\EditGroup::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|