You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
Suppose you have an attribute named `password` in your model class, but don't want to store the plain-text version in the database. The pragmatic thing to do would be to store the hash of the original content. Worry not, Ardent is fully capable of transmogrifying any number of secure fields automatically for you!
365
366
@@ -373,3 +374,39 @@ class User extends \LaravelBook\Ardent\Ardent {
373
374
```
374
375
375
376
Ardent will automatically replace the plain-text password attribute with secure hash checksum and save it to database. It uses the Laravel `Hash::make()` method internally to generate hash.
377
+
378
+
379
+
<aname="secure"></a>
380
+
## Automatically Transform Secure-Text Attributes
381
+
Ardent can assist you with unique updates. According to the Lavavel Documentation, when you update (and therefore validate) a field with a unique rule, you have to pass in the unique ID of the record you are updating. Without passing this ID, validation will fail because Laravel's Validator will think this record is a duplicate.
382
+
383
+
From the Laravel Documentation:
384
+
385
+
```php
386
+
'email' => 'unique:users,email,10'
387
+
```
388
+
389
+
In the past, programmers had to manually manage the passing of the ID and changing of the ruleset to include the ID at runtime. Not so with Ardent. Simply set up your rules with `unique`, call function `updateUniques` and Ardent will take care of the rest.
390
+
391
+
#### Example:
392
+
393
+
In your extended model define your rules
394
+
395
+
```php
396
+
public static $rules = array(
397
+
'email' => 'required|email|unique',
398
+
'password' => 'required|between:4,20|confirmed',
399
+
'password_confirmation' => 'between:4,20',
400
+
);
401
+
```
402
+
403
+
In your controller, when you need to update, simply call
404
+
405
+
```php
406
+
$model->updateUniques();
407
+
```
408
+
409
+
If required, you can runtime pass rules to `updateUniques`, otherwise it will use the static rules provided by your model.
410
+
411
+
Note that in the above example of the rules, we did not tell the Validator which table or even which field to use as it is described in the Laravel Documentation (ie `unique:users,email,10`). Ardent is clever enough to figure it out. (Thank you to github user @Sylph)
0 commit comments