Skip to content

Commit 8c730b3

Browse files
authored
Update crud-fields.md
1 parent fe249a0 commit 8c730b3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

4.0/crud-fields.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,37 @@ Show radios according to an associative array you give the input and let the use
832832
]
833833
```
834834

835+
Please note that this will NOT hash/encrypt the string before it stores it to the database. You need to hash the password manually. The most popular way to do that are:
836+
837+
1. Using [a mutator on your Model](https://laravel.com/docs/7.x/eloquent-mutators#defining-a-mutator). For example:
838+
839+
```php
840+
public function setPasswordAttribute($value) {
841+
$this->attributes['password'] = Hash::make($value);
842+
}
843+
```
844+
845+
2. By overwriting the Create/Update operation methods, inside the Controller. For example:
846+
```php
847+
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }
848+
849+
public function store()
850+
{
851+
$this->crud->request = $this->crud->validateRequest();
852+
853+
// Encrypt password if specified.
854+
if ($request->input('password')) {
855+
$request->request->set('password', Hash::make($request->input('password')));
856+
} else {
857+
$request->request->remove('password');
858+
}
859+
860+
return $this->traitStore();
861+
}
862+
```
863+
864+
Take a look at [this working code](https://github.com/Laravel-Backpack/PermissionManager/blob/master/src/app/Http/Controllers/UserCrudController.php#L103-L124) for a more accurate example.
865+
835866
Input preview:
836867

837868
![CRUD Field - radio](https://backpackforlaravel.com/uploads/docs-4-0/fields/radio.png)

0 commit comments

Comments
 (0)