components([ TextInput::make('name') ->label('Nama') ->placeholder('John Doe') ->autocomplete(false) ->autofocus() ->required() ->maxLength(100), TextInput::make('email') ->label('Alamat Surel') ->placeholder('johndoe@example.com') ->autocomplete(false) ->required() ->maxLength(254) ->email() ->unique(ignoreRecord: true), TextInput::make('username') ->label('Nama Pengguna') ->placeholder('johndoe') ->autocomplete(false) ->required() ->minLength(5) ->maxLength(20) ->regex('/^[a-zA-Z0-9_.-]+$/') ->unique(ignoreRecord: true), Select::make('roles') ->label('Peran') ->required() ->relationship('roles', 'name', function (Builder $query): Builder { return $query->whereNot('name', RoleEnum::DEVELOPER); }) ->multiple() ->preload() ->searchable(), Hidden::make('password') ->default(fn (): string => config('auth.password_default')) ->visibleOn('create'), Placeholder::make('default_password_info') ->label('Informasi Kata Sandi') ->content( 'Kata sandi bawaan untuk pengguna baru adalah: ' .config('auth.password_default'). '' ) ->html() ->visibleOn('create'), ]) ->columns(1); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('name') ->label('Nama') ->searchable() ->sortable(), TextColumn::make('email') ->label('Alamat Surel') ->searchable() ->sortable(), TextColumn::make('username') ->label('Nama Pengguna') ->searchable() ->sortable(), TextColumn::make('roles.name') ->label('Peran') ->searchable() ->sortable() ->badge() ->getStateUsing(fn (User $record): array => $record->roles->pluck('name', 'id')->toArray()), ...TimestampColumns::make(), ]) ->filters([ TrashedFilter::make() ->native(false) ->visible(fn (): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER)), ]) ->recordActions([ EditAction::make() ->modalWidth(Width::Large), DeleteAction::make(), ForceDeleteAction::make(), RestoreAction::make(), ChangePasswordAction::make('changePassword'), ]) ->toolbarActions([ BulkActionGroup::make([ ...DefaultBulkActions::make('Pengguna'), ]), ]) ->emptyStateIcon(Heroicon::UserGroup) ->emptyStateDescription('Setelah Anda membubat data pertama, maka akan muncul disini.') ->defaultSort('created_at', 'desc') ->deferFilters(false); } public static function getPages(): array { return [ 'index' => ManageUsers::route('/'), ]; } public static function getRecordRouteBindingEloquentQuery(): Builder { return parent::getRecordRouteBindingEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } public static function getEloquentQuery(): Builder { return static::getModel()::query()->withoutDeveloper(); } }