@@ -38,7 +38,9 @@ protected function setupCreateOperation()
3838 CRUD::field('name')->validationRules('required|min:5');
3939 CRUD::field('email')->validationRules('required|email|unique:users,email');
4040 CRUD::field('password')->validationRules('required');
41-
41+
42+ // if you are using Laravel 10+ your User model should already include the password hashing in the model casts.
43+ // if that's the case, you can skip this step. You can check your model $casts property or `casts()` method.
4244 \App\Models\User::creating(function ($entry) {
4345 $entry->password = \Hash::make($entry->password);
4446 });
@@ -54,13 +56,23 @@ protected function setupUpdateOperation()
5456 CRUD::field('email')->validationRules('required|email|unique:users,email,'.CRUD::getCurrentEntryId());
5557 CRUD::field('password')->hint('Type a password to change it.');
5658
59+ // if you are using Laravel 10+ your User model should already include the password hashing in the model casts.
60+ // if that's the case, you just need to keep the old password unchanged when the user is updated.
5761 \App\Models\User::updating(function ($entry) {
5862 if (request('password') == null) {
59- $entry->password = $entry->getOriginal('password');
60- } else {
61- $entry->password = \Hash::make(request('password'));
63+ $entry->password = $entry->getOriginal('password');
6264 }
6365 });
66+
67+ // in case you are using an older version of Laravel, or you are not casting your password in the model, you need
68+ // to manually hash the password when it's updated by the user
69+ \App\Models\User::updating(function ($entry) {
70+ if (request('password') == null) {
71+ $entry->password = $entry->getOriginal('password');
72+ } else {
73+ $entry->password = \Hash::make(request('password'));
74+ }
75+ });
6476 }
6577 </code ></pre >
6678 </p >
0 commit comments