133 lines
4.3 KiB
PHP
133 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\UserResource\Pages;
|
|
use App\Filament\Resources\UserResource\RelationManagers;
|
|
use App\Models\User;
|
|
use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\Section;
|
|
use Filament\Forms\Components\TextInput;
|
|
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;
|
|
use Illuminate\Support\Str;
|
|
|
|
class UserResource extends Resource implements HasShieldPermissions
|
|
{
|
|
protected static ?string $model = User::class;
|
|
|
|
protected static ?string $navigationGroup = 'Settings';
|
|
|
|
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()
|
|
->default(Str::password(15))
|
|
->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'
|
|
];
|
|
}
|
|
}
|