Skip to content

Commit

Permalink
Merge pull request #5525 from Laravel-Backpack/update-getting-started
Browse files Browse the repository at this point in the history
update getting started
  • Loading branch information
pxpm authored May 20, 2024
2 parents 90f1482 + 6922afb commit 7ddec50
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/resources/views/ui/inc/getting_started.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ protected function setupCreateOperation()
CRUD::field('name')->validationRules('required|min:5');
CRUD::field('email')->validationRules('required|email|unique:users,email');
CRUD::field('password')->validationRules('required');


// if you are using Laravel 10+ your User model should already include the password hashing in the model casts.
// if that's the case, you can skip this step. You can check your model $casts property or `casts()` method.
\App\Models\User::creating(function ($entry) {
$entry->password = \Hash::make($entry->password);
});
Expand All @@ -54,13 +56,23 @@ protected function setupUpdateOperation()
CRUD::field('email')->validationRules('required|email|unique:users,email,'.CRUD::getCurrentEntryId());
CRUD::field('password')->hint('Type a password to change it.');

// if you are using Laravel 10+ your User model should already include the password hashing in the model casts.
// if that's the case, you just need to keep the old password unchanged when the user is updated.
\App\Models\User::updating(function ($entry) {
if (request('password') == null) {
$entry->password = $entry->getOriginal('password');
} else {
$entry->password = \Hash::make(request('password'));
$entry->password = $entry->getOriginal('password');
}
});

// in case you are using an older version of Laravel, or you are not casting your password in the model, you need
// to manually hash the password when it's updated by the user
\App\Models\User::updating(function ($entry) {
if (request('password') == null) {
$entry->password = $entry->getOriginal('password');
} else {
$entry->password = \Hash::make(request('password'));
}
});
}
</code></pre>
</p>
Expand Down

0 comments on commit 7ddec50

Please sign in to comment.