Files
2026-03-20 21:47:02 +05:00

128 lines
4.2 KiB
PHP
Executable File

<?php
namespace App\Filament\Resources;
use App\Containers\User\Models\User;
use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class UserResource extends Resource implements HasShieldPermissions
{
protected static ?string $model = User::class;
protected static ?string $navigationGroup = 'Настройки приложения';
protected static ?string $pluralLabel = 'Пользователи';
protected static ?string $navigationIcon = 'heroicon-o-user-circle';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make()->schema([
Forms\Components\Grid::make()->schema([
Forms\Components\TextInput::make('name')
->label('ФИО')
->required()
->maxLength(255)
->live(onBlur: true),
Forms\Components\TextInput::make('email')
->label('Email')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Forms\Components\DateTimePicker::make('email_verified_at')->label('Почта подтверждена'),
Forms\Components\TextInput::make('password')
->label('Пароль')
->password()
->required(fn (string $context): bool => $context === 'create')
->dehydrated(fn ($state) => filled($state))
->maxLength(255),
Forms\Components\Select::make('roles')
->label('Роль')
->relationship('roles', 'name')
->multiple()
->preload()
->searchable(),
Forms\Components\Select::make('permissions')
->label('Разрешения')
->relationship('permissions', 'name')
->multiple()
->preload()
->searchable()
]),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->label('ФИО')
->searchable()->sortable(),
Tables\Columns\TextColumn::make('email')->label('Email')
->searchable()->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
RelationManagers\UserDetailRelationManager::class
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
public static function getPermissionPrefixes(): array
{
return [
'view',
'view_any',
'create',
'update',
'delete',
'delete_any',
'invite'
];
}
}