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

Commit

Permalink
Added changes as per Sylph's post. Now adds support for custom primar…
Browse files Browse the repository at this point in the history
…y keys, auto population of table names
  • Loading branch information
nightowl77 authored and igorsantos07 committed Oct 15, 2013
1 parent df3f4f3 commit d36660d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class User extends \LaravelBook\Ardent\Ardent {
public static $rules = array(
'name' => 'required|between:4,16',
'email' => 'required|email',
'password' => 'required|alpha_num|between:4,8|confirmed',
'password_confirmation' => 'required|alpha_num|between:4,8',
'password' => 'required|alpha_num|between:4,8|confirmed',
'password_confirmation' => 'required|alpha_num|between:4,8',
);
}
```
Expand Down Expand Up @@ -359,9 +359,8 @@ function __construct() {
}
```


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

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!

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


<a name="uniquerules"></a>
## Updates with Unique Rules

<a name="secure"></a>
## Automatically Transform Secure-Text Attributes
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.

From the Laravel Documentation:
Expand Down
4 changes: 3 additions & 1 deletion src/LaravelBook/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ protected function buildUniqueExclusionRules(array $rules = array()) {
// if the 3rd param was set, do not overwrite it
if (!is_numeric(@$params[2])) $params[2] = $this->id;


$rule = implode(',', $params);
}
}
Expand All @@ -779,7 +780,8 @@ protected function buildUniqueExclusionRules(array $rules = array()) {
}

/**
* Update a model already saved in the database.
* Update a model, but filter uniques first to ensure a unique validation rule
* does not fire
*
* @param array $rules
* @param array $customMessages
Expand Down

0 comments on commit d36660d

Please sign in to comment.