File tree Expand file tree Collapse file tree 2 files changed +13
-20
lines changed
Expand file tree Collapse file tree 2 files changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -43,23 +43,15 @@ public static function form(Form $form): Form
4343 Forms \Components \TextInput::make ('password ' )
4444 ->required ()
4545 ->password ()
46- ->dehydrateStateUsing (fn ($ state ) => Hash::make ($ state ))
47- ->visible (fn ($ livewire ) => $ livewire instanceof CreateUser)
48- ->rule (Password::default ()),
49- Forms \Components \TextInput::make ('new_password ' )
50- ->password ()
51- ->label ('New Password ' )
52- ->nullable ()
53- ->rule (Password::default ())
54- ->visible (fn ($ livewire ) => $ livewire instanceof EditUser)
55- ->dehydrated (false ),
56- Forms \Components \TextInput::make ('new_password_confirmation ' )
46+ ->required (fn (string $ context ) => $ context === 'create ' )
47+ ->nullable (fn (string $ context ) => $ context === 'edit ' )
48+ ->maxLength (60 ),
49+ Forms \Components \TextInput::make ('password_confirmation ' )->label ('Confirm Password ' )
50+ ->required ()
5751 ->password ()
58- ->label ( ' Confirm New Password ' )
59- ->rule ( ' required ' , fn ($ get ) => ( bool ) $ get ( ' new_password ' ) )
52+ ->required ( fn ( string $ context ) => $ context === ' create ' )
53+ ->nullable ( fn (string $ context ) => $ context === ' edit ' )
6054 ->same ('new_password ' )
61- ->visible (fn ($ livewire ) => $ livewire instanceof EditUser)
62- ->dehydrated (false ),
6355 ])
6456 ->columns (1 )
6557 ->columnSpan ([
Original file line number Diff line number Diff line change @@ -18,12 +18,13 @@ protected function getHeaderActions(): array
1818 ];
1919 }
2020
21- public function beforeSave ()
21+ protected function mutateFormDataBeforeSave ( array $ data ): array
2222 {
23- if (! array_key_exists ( ' new_password ' , $ this -> data ) || ! filled ( $ this -> data ['new_password ' ])) {
24- return ;
25- }
23+ if (!isset ( $ data[ ' password ' ] ) || empty ( $ data ['password ' ])) {
24+ unset( $ data [ ' password ' ]) ;
25+ }
2626
27- $ this -> record -> password = Hash:: make ( $ this -> data [ ' new_password ' ]) ;
27+ return $ data ;
2828 }
29+
2930}
You can’t perform that action at this time.
0 commit comments