Skip to content

Commit 319da3e

Browse files
authored
feat: add random password generator in user edit
1 parent fc70172 commit 319da3e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/Filament/Resources/UserResource.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use Eclipse\Core\Filament\Resources;
88
use Eclipse\Core\Models\User;
99
use Filament\Forms;
10+
use Filament\Forms\Components\Actions\Action;
1011
use Filament\Forms\Form;
12+
use Filament\Forms\Set;
1113
use Filament\Infolists\Components\Group;
1214
use Filament\Infolists\Components\Section;
1315
use Filament\Infolists\Components\SpatieMediaLibraryImageEntry;
@@ -23,6 +25,7 @@
2325
use Illuminate\Database\Eloquent\Builder;
2426
use Illuminate\Database\Eloquent\SoftDeletingScope;
2527
use Illuminate\Support\Facades\Hash;
28+
use Illuminate\Support\Str;
2629
use pxlrbt\FilamentExcel\Actions\Tables\ExportBulkAction;
2730
use STS\FilamentImpersonate\Tables\Actions\Impersonate;
2831

@@ -56,7 +59,16 @@ public static function form(Form $form): Form
5659
->dehydrateStateUsing(fn ($state) => Hash::make($state))
5760
->dehydrated(fn ($state) => filled($state))
5861
->required(fn (string $context): bool => $context === 'create')
59-
->label(fn (string $context): string => $context === 'create' ? 'Password' : 'Set new password'),
62+
->label(fn (string $context): string => $context === 'create' ? 'Password' : 'Set new password')
63+
->suffixAction(
64+
Action::make('randomPassword')
65+
->icon('heroicon-s-arrow-path')
66+
->tooltip(__('Random password generator'))
67+
->color('gray')
68+
->action(
69+
fn (Set $set) => $set('password', Str::password(16))
70+
)
71+
),
6072
Forms\Components\Select::make('roles')
6173
->relationship('roles', 'name')
6274
->saveRelationshipsUsing(function (User $record, $state) {

0 commit comments

Comments
 (0)