Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit d36660d

Browse files
nightowl77igorsantos07
authored andcommitted
Added changes as per Sylph's post. Now adds support for custom primary keys, auto population of table names
1 parent df3f4f3 commit d36660d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class User extends \LaravelBook\Ardent\Ardent {
141141
public static $rules = array(
142142
'name' => 'required|between:4,16',
143143
'email' => 'required|email',
144-
'password' => 'required|alpha_num|between:4,8|confirmed',
145-
'password_confirmation' => 'required|alpha_num|between:4,8',
144+
'password' => 'required|alpha_num|between:4,8|confirmed',
145+
'password_confirmation' => 'required|alpha_num|between:4,8',
146146
);
147147
}
148148
```
@@ -359,9 +359,8 @@ function __construct() {
359359
}
360360
```
361361

362-
363-
<a name="secure"></a>
364-
## Automatically Transform Secure-Text Attributes
362+
<a name="uniquerules"></a>
363+
## Updates with Unique Rules
365364

366365
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!
367366

@@ -377,9 +376,8 @@ class User extends \LaravelBook\Ardent\Ardent {
377376
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.
378377

379378

380-
<a name="uniquerules"></a>
381-
## Updates with Unique Rules
382-
379+
<a name="secure"></a>
380+
## Automatically Transform Secure-Text Attributes
383381
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.
384382

385383
From the Laravel Documentation:

src/LaravelBook/Ardent/Ardent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ protected function buildUniqueExclusionRules(array $rules = array()) {
770770
// if the 3rd param was set, do not overwrite it
771771
if (!is_numeric(@$params[2])) $params[2] = $this->id;
772772

773+
773774
$rule = implode(',', $params);
774775
}
775776
}
@@ -779,7 +780,8 @@ protected function buildUniqueExclusionRules(array $rules = array()) {
779780
}
780781

781782
/**
782-
* Update a model already saved in the database.
783+
* Update a model, but filter uniques first to ensure a unique validation rule
784+
* does not fire
783785
*
784786
* @param array $rules
785787
* @param array $customMessages

0 commit comments

Comments
 (0)