Example UserResource with Password reset button

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('changePassword')
->icon('heroicon-o-shield-check')
->label('Change password')
->form([
Forms\Components\TextInput::make('new_password')
->password()
->label('New password')
->required()
->rule(Password::default()),
Forms\Components\TextInput::make('new_password_confirmation')
->password()
->label('Retype new password')
->required()
->same('new_password')
->rule(Password::default()),
])
->action(function (User $record, array $data) {
$record->update([
'password' => Hash::make($data['new_password'])
]);
Notification::make()
->title('Password changed')
->success()
->send();
}),
])
}


public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('changePassword')
->icon('heroicon-o-shield-check')
->label('Change password')
->form([
Forms\Components\TextInput::make('new_password')
->password()
->label('New password')
->required()
->rule(Password::default()),
Forms\Components\TextInput::make('new_password_confirmation')
->password()
->label('Retype new password')
->required()
->same('new_password')
->rule(Password::default()),
])
->action(function (User $record, array $data) {
$record->update([
'password' => Hash::make($data['new_password'])
]);
Notification::make()
->title('Password changed')
->success()
->send();
}),
])
}


public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
1 Reply
tuto1902
tuto190212mo ago
Thank you so much for sharing