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

Commit f649633

Browse files
committed
updated with upstream
2 parents d20f68a + 51b99b4 commit f649633

File tree

6 files changed

+247
-115
lines changed

6 files changed

+247
-115
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Ardent's Changelog
2+
==================
3+
4+
Please, look at the [project's release][1] page :)
5+
6+
[1]:https://github.com/laravelbook/ardent/releases

LICENSE renamed to LICENSE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Copyright (c) 2013, Max Ehsan
2-
All rights reserved.
1+
# [BSD 3-clause New License](http://choosealicense.com/licenses/bsd-3-clause/)
2+
3+
### Copyright (c) 2015 - Max Ehsan, Igor Santos. All rights reserved
34

45
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
56

@@ -21,4 +22,4 @@ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2122
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2223
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2324
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24-
SUCH DAMAGE.
25+
SUCH DAMAGE.

README.md

Lines changed: 91 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
#Ardent
1+
Ardent
2+
======
23

3-
Self-validating smart models for Laravel Framework 4's Eloquent O/RM.
4+
[![Latest Stable Version](https://poser.pugx.org/laravelbook/ardent/v/stable.svg)](https://packagist.org/packages/laravelbook/ardent)
5+
[![License](https://poser.pugx.org/laravelbook/ardent/license.svg)](https://packagist.org/packages/laravelbook/ardent)
6+
[![Total Downloads](https://poser.pugx.org/laravelbook/ardent/downloads.svg)](https://packagist.org/packages/laravelbook/ardent)
7+
[![Monthly Downloads](https://poser.pugx.org/laravelbook/ardent/d/monthly.png)](https://packagist.org/packages/laravelbook/ardent)
8+
[![Daily Downloads](https://poser.pugx.org/laravelbook/ardent/d/daily.png)](https://packagist.org/packages/laravelbook/ardent)
9+
10+
11+
Self-validating smart models for Laravel Framework 4's Eloquent ORM.
412

513
Based on the Aware bundle for Laravel 3 by Colby Rabideau.
614

7-
Copyright (C) 2013 Max Ehsan <[http://laravelbook.com/](http://laravelbook.com/)>
15+
Copyright (C) 2013-2015 [Max Ehsan](http://laravelbook.com/) & [Igor Santos](http://www.igorsantos.com.br)
16+
17+
## Changelog
18+
19+
Visit our [Releases list](https://github.com/laravelbook/ardent/releases). The changelog is made there :)
820

921
## Installation
1022

11-
Add `laravelbook/ardent` as a requirement to `composer.json`:
23+
Add `laravelbook/ardent` as a requirement to `composer.json` (see our latest stable version on the badges!):
1224

1325
```javascript
1426
{
1527
"require": {
16-
"laravelbook/ardent": "dev-master"
28+
"laravelbook/ardent": "2.*"
1729
}
1830
}
1931
```
@@ -38,26 +50,28 @@ to your database, obviously):
3850
'password' => 'h4ckr',
3951
'charset' => 'utf8',
4052
'collation' => 'utf8_unicode_ci'
41-
));
53+
), 'en'); //English is the default messages language, may be left empty
4254
```
4355

56+
------------------------------------------------------------------------------------------------------------
57+
4458
## Documentation
4559

46-
* [Introduction](#intro)
47-
* [Getting Started](#start)
48-
* [Effortless Validation with Ardent](#validation)
49-
* [Retrieving Validation Errors](#errors)
50-
* [Overriding Validation](#override)
51-
* [Custom Validation Error Messages](#messages)
52-
* [Custom Validation Rules](#rules)
53-
* [Model hooks](#modelhooks)
54-
* [Cleaner definition of relationships](#relations)
55-
* [Automatically Hydrate Ardent Entities](#hydra)
56-
* [Automatically Purge Redundant Form Data](#purge)
57-
* [Automatically Transform Secure-Text Attributes](#secure)
58-
* [Updates with Unique Rules] (#uniquerules)
59-
60-
<a name="start"></a>
60+
* [Introduction](#introduction)
61+
* [Getting Started](#getting-started)
62+
* [Effortless Validation with Ardent](#effortless-validation-with-ardent)
63+
* [Retrieving Validation Errors](#retrieving-validation-errors)
64+
* [Overriding Validation](#overriding-validation)
65+
* [Custom Validation Error Messages](#custom-validation-error-messages)
66+
* [Custom Validation Rules](#custom-validation-rules)
67+
* [Model hooks](#model-hooks-since-20)
68+
* [Cleaner definition of relationships](#cleaner-definition-of-relationships-since-20)
69+
* [Automatically Hydrate Ardent Entities](#automatically-hydrate-ardent-entities)
70+
* [Automatically Purge Redundant Form Data](#automatically-purge-redundant-form-data)
71+
* [Automatically Transform Secure-Text Attributes](#automatically-transform-secure-text-attributes)
72+
* [Updates with Unique Rules](#updates-with-unique-rules)
73+
74+
6175
## Introduction
6276

6377
How often do you find yourself re-creating the same boilerplate code in the applications you build? Does this typical form processing code look all too familiar to you?
@@ -116,7 +130,7 @@ For example, user registration or blog post submission is a common coding requir
116130

117131
**No more repetitive brain strain injury for you!**
118132

119-
<a name="start"></a>
133+
120134
## Getting Started
121135

122136
`Ardent` aims to extend the `Eloquent` base class without changing its core functionality. Since `Ardent` itself is a descendant of `Illuminate\Database\Eloquent\Model`, all your `Ardent` models are fully compatible with `Eloquent` and can harness the full power of Laravels awesome OR/M.
@@ -131,10 +145,10 @@ class User extends Ardent {}
131145

132146
> **Note:** You can freely *co-mingle* your plain-vanilla Eloquent models with Ardent descendants. If a model object doesn't rely upon user submitted content and therefore doesn't require validation - you may leave the Eloquent model class as it is.
133147
134-
<a name="validation"></a>
148+
135149
## Effortless Validation with Ardent
136150

137-
Ardent models use Laravel's built-in [Validator class](http://four.laravel.com/docs/validation). Defining validation rules for a model is simple and is typically done in your model class as a static variable:
151+
Ardent models use Laravel's built-in [Validator class](http://laravel.com/docs/validation). Defining validation rules for a model is simple and is typically done in your model class as a static variable:
138152

139153
```php
140154
class User extends \LaravelBook\Ardent\Ardent {
@@ -147,7 +161,7 @@ class User extends \LaravelBook\Ardent\Ardent {
147161
}
148162
```
149163

150-
> **Note**: you're free to use the [array syntax](http://four.laravel.com/docs/validation#basic-usage) for validation rules as well.
164+
> **Note**: you're free to use the [array syntax](http://laravel.com/docs/validation#basic-usage) for validation rules as well.
151165
152166
Ardent models validate themselves automatically when `Ardent->save()` is called.
153167

@@ -162,7 +176,7 @@ $success = $user->save(); // returns false if model is invalid
162176

163177
> **Note:** You can also validate a model at any time using the `Ardent->validate()` method.
164178
165-
<a name="errors"></a>
179+
166180
## Retrieving Validation Errors
167181

168182
When an Ardent model fails to validate, a `Illuminate\Support\MessageBag` object is attached to the Ardent object which contains validation failure messages.
@@ -171,9 +185,9 @@ Retrieve the validation errors message collection instance with `Ardent->errors(
171185

172186
Retrieve all validation errors with `Ardent->errors()->all()`. Retrieve errors for a *specific* attribute using `Ardent->validationErrors->get('attribute')`.
173187

174-
> **Note:** Ardent leverages Laravel's MessagesBag object which has a [simple and elegant method](http://four.laravel.com/docs/validation#working-with-error-messages) of formatting errors.
188+
> **Note:** Ardent leverages Laravel's MessagesBag object which has a [simple and elegant method](http://laravel.com/docs/validation#working-with-error-messages) of formatting errors.
189+
175190

176-
<a name="overide"></a>
177191
## Overriding Validation
178192

179193
There are two ways to override Ardent's validation:
@@ -191,10 +205,10 @@ An array that is **not empty** will override the rules or custom error messages
191205

192206
> **Note:** the default value for `$rules` and `$customMessages` is empty `array()`; thus, if you pass an `array()` nothing will be overriden.
193207
194-
<a name="messages"></a>
195-
## Custom Error Messages
196208

197-
Just like the Laravel Validator, Ardent lets you set custom error messages using the [same syntax](http://four.laravel.com/docs/validation#custom-error-messages).
209+
## Custom Validation Error Messages
210+
211+
Just like the Laravel Validator, Ardent lets you set custom error messages using the [same syntax](http://laravel.com/docs/validation#custom-error-messages).
198212

199213
```php
200214
class User extends \LaravelBook\Ardent\Ardent {
@@ -205,48 +219,12 @@ class User extends \LaravelBook\Ardent\Ardent {
205219
}
206220
```
207221

208-
<a name="rules"></a>
209-
## Custom Validation Rules
210-
211-
You can create custom validation rules the [same way](http://four.laravel.com/docs/validation#custom-validation-rules) you would for the Laravel Validator.
212222

213-
<a name="hydra"></a>
214-
## Automatically Hydrate Ardent Entities
215-
216-
Ardent is capable of hydrating your entity model class from the form input submission automatically!
217-
218-
Let's see it action. Consider this snippet of code:
219-
220-
```php
221-
$user = new User;
222-
$user->name = Input::get('name');
223-
$user->email = Input::get('email');
224-
$user->password = Hash::make(Input::get('password'));
225-
$user->save();
226-
```
227-
228-
Let's invoke the *magick* of Ardent and rewrite the previous snippet:
229-
230-
```php
231-
$user = new User;
232-
$user->save();
233-
```
234-
235-
That's it! All we've done is remove the boring stuff.
236-
237-
Believe it or not, the code above performs essentially the same task as its older, albeit rather verbose sibling. Ardent populates the model object with attributes from user submitted form data. No more hair-pulling trying to find out which Eloquent property you've forgotten to populate. Let Ardent take care of the boring stuff, while you get on with the fun stuffs!
238-
It follows the same [mass assignment rules](http://four.laravel.com/docs/eloquent#mass-assignment) internally, depending on the `$fillable`/`$guarded` properties.
223+
## Custom Validation Rules
239224

240-
To enable the auto-hydration feature, simply set the `$autoHydrateEntityFromInput` instance variable to `true` in your model class. However, to prevent filling pre-existent properties, if you want auto-hydration also for update scenarios, you should use instead `$forceEntityHydrationFromInput`:
225+
You can create custom validation rules the [same way](http://laravel.com/docs/validation#custom-validation-rules) you would for the Laravel Validator.
241226

242-
```php
243-
class User extends \LaravelBook\Ardent\Ardent {
244-
public $autoHydrateEntityFromInput = true; // hydrates on new entries' validation
245-
public $forceEntityHydrationFromInput = true; // hydrates whenever validation is called
246-
}
247-
```
248227

249-
<a name="modelhooks"></a>
250228
## Model Hooks (since [2.0](https://github.com/laravelbook/ardent/tree/v2.0.0))
251229

252230
Ardent provides some syntatic sugar over Eloquent's model events: traditional model hooks. They are an easy way to hook up additional operations to different moments in your model life. They can be used to do additional clean-up work before deleting an entry, doing automatic fixes after validation occurs or updating related models after an update happens.
@@ -295,12 +273,12 @@ $user->save(array(), array(), array(),
295273

296274
> **Note:** the closures should have one parameter as it will be passed a reference to the model being saved.
297275
298-
<a name="relations"></a>
299-
## Cleaner definition of relationships (since [2.0](https://github.com/laravelbook/ardent/tree/v2.0.0))
276+
277+
## Cleaner definition of relationships (since [2.0](https://github.com/laravelbook/ardent/tree/v2.0.0))
300278

301279
Have you ever written an Eloquent model with a bunch of relations, just to notice how cluttered your class is, with all those one-liners that have almost the same content as the method name itself?
302280

303-
In Ardent you can cleanly define your relationships in an array with their information, and they will work just like if you had defined they in methods. Here's an example:
281+
In Ardent you can cleanly define your relationships in an array with their information, and they will work just like if you had defined them in methods. Here's an example:
304282

305283
```php
306284
class User extends \LaravelBook\Ardent\Ardent {
@@ -334,10 +312,46 @@ or one of the related constants (`Ardent::HAS_MANY` or `Ardent::MORPH_ONE` for e
334312

335313
> **Note:** This feature was based on the easy [relations on Yii 1.1 ActiveRecord](http://www.yiiframework.com/doc/guide/1.1/en/database.arr#declaring-relationship).
336314
337-
<a name="purge"></a>
315+
316+
## Automatically Hydrate Ardent Entities
317+
318+
Ardent is capable of hydrating your entity model class from the form input submission automatically!
319+
320+
Let's see it action. Consider this snippet of code:
321+
322+
```php
323+
$user = new User;
324+
$user->name = Input::get('name');
325+
$user->email = Input::get('email');
326+
$user->password = Hash::make(Input::get('password'));
327+
$user->save();
328+
```
329+
330+
Let's invoke the *magick* of Ardent and rewrite the previous snippet:
331+
332+
```php
333+
$user = new User;
334+
$user->save();
335+
```
336+
337+
That's it! All we've done is remove the boring stuff.
338+
339+
Believe it or not, the code above performs essentially the same task as its older, albeit rather verbose sibling. Ardent populates the model object with attributes from user submitted form data. No more hair-pulling trying to find out which Eloquent property you've forgotten to populate. Let Ardent take care of the boring stuff, while you get on with the fun stuffs!
340+
It follows the same [mass assignment rules](http://laravel.com/docs/eloquent#mass-assignment) internally, depending on the `$fillable`/`$guarded` properties.
341+
342+
To enable the auto-hydration feature, simply set the `$autoHydrateEntityFromInput` instance variable to `true` in your model class. However, to prevent filling pre-existent properties, if you want auto-hydration also for update scenarios, you should use instead `$forceEntityHydrationFromInput`:
343+
344+
```php
345+
class User extends \LaravelBook\Ardent\Ardent {
346+
public $autoHydrateEntityFromInput = true; // hydrates on new entries' validation
347+
public $forceEntityHydrationFromInput = true; // hydrates whenever validation is called
348+
}
349+
```
350+
351+
338352
## Automatically Purge Redundant Form Data
339353

340-
Ardent models can *auto-magically* purge redundant input data (such as *password confirmation* fields) - so that the extra data is never saved to database. Ardent will use the confirmation fields to validate form input, then prudently discard these attributes before saving the model instance to database!
354+
Ardent models can *auto-magically* purge redundant input data (such as *password confirmation*, hidden CSRF `_token` or custom HTTP `_method` fields) - so that the extra data is never saved to database. Ardent will use the confirmation fields to validate form input, then prudently discard these attributes before saving the model instance to database!
341355

342356
To enable this feature, simply set the `$autoPurgeRedundantAttributes` instance variable to `true` in your model class:
343357

@@ -359,7 +373,8 @@ function __construct($attributes = array()) {
359373
};
360374
}
361375
```
362-
<a name="secure"></a>
376+
377+
363378
## Automatically Transform Secure-Text Attributes
364379

365380
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!
@@ -375,7 +390,7 @@ class User extends \LaravelBook\Ardent\Ardent {
375390

376391
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.
377392

378-
<a name="uniquerules"></a>
393+
379394
## Updates with Unique Rules
380395

381396
Ardent can assist you with unique updates. According to the Laravel 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.

composer.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
"homepage": "http://laravelbook.com/",
77
"license": "BSD-3-Clause",
88
"authors": [
9-
{
10-
"name": "Max Ehsan",
11-
"homepage": "http://laravelbook.com/",
12-
"email": "[email protected]",
13-
"role": "Developer"
14-
},
159
{
1610
"name": "Igor Santos",
1711
"homepage": "http://www.igorsantos.com.br",

0 commit comments

Comments
 (0)