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

Commit 6e71b8b

Browse files
committed
Small improvements on code style to follow the project style guide
1 parent 22880db commit 6e71b8b

File tree

1 file changed

+40
-58
lines changed

1 file changed

+40
-58
lines changed

README.md

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,26 @@ to your database, obviously):
6161
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?
6262

6363
```php
64-
Route::post( 'register', function () {
64+
Route::post('register', function () {
6565
$rules = array(
66-
'name' => 'required|min:3|max:80|alpha_dash',
67-
'email' => 'required|between:3,64|email|unique:users',
68-
'password' =>'required|alpha_num|between:4,8|confirmed',
69-
'password_confirmation'=>'required|alpha_num|between:4,8'
66+
'name' => 'required|min:3|max:80|alpha_dash',
67+
'email' => 'required|between:3,64|email|unique:users',
68+
'password' => 'required|alpha_num|between:4,8|confirmed',
69+
'password_confirmation' => 'required|alpha_num|between:4,8'
7070
);
7171

72-
$validator = Validator::make( Input::all(), $rules );
72+
$validator = Validator::make(Input::all(), $rules);
7373

74-
if ( $validator->passes() ) {
75-
User::create( array(
76-
'name' => Input::get( 'real_name' ),
77-
'email' => Input::get( 'email' ),
78-
'password' => Hash::make( Input::get( 'password' ) )
79-
) );
74+
if ($validator->passes()) {
75+
User::create(array(
76+
'name' => Input::get('name'),
77+
'email' => Input::get('email'),
78+
'password' => Hash::make(Input::get('password'))
79+
));
8080

81-
return Redirect::to( '/' )->with( 'message', 'Thanks for registering!' );
81+
return Redirect::to('/')->with('message', 'Thanks for registering!');
8282
} else {
83-
return Redirect::to( '/' )->withErrors( $v->getMessages() );
83+
return Redirect::to('/')->withErrors($v->getMessages());
8484
}
8585
}
8686
);
@@ -91,12 +91,12 @@ Implementing this yourself often results in a lot of repeated boilerplate code.
9191
What if someone else did all the heavy-lifting for you? What if, instead of regurgitating the above mess, all you needed to type was these few lines?...
9292

9393
```php
94-
Route::post( 'register', function () {
94+
Route::post('register', function() {
9595
$user = new User;
96-
if ( $user->save() ) {
97-
return Redirect::to( '/' )->with( 'message', 'Thanks for registering!' );
96+
if ($user->save()) {
97+
return Redirect::to('/')->with('message', 'Thanks for registering!');
9898
} else {
99-
return Redirect::to( '/' )->withErrors( $user->errors() );
99+
return Redirect::to('/')->withErrors($user->errors());
100100
}
101101
}
102102
);
@@ -119,7 +119,7 @@ For example, user registration or blog post submission is a common coding requir
119119

120120
`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.
121121

122-
To create a new Ardent model, simply make your model class derive from the `Ardent` base class:
122+
To create a new Ardent model, simply make your model class derive from the `Ardent` base class. In the next examples we will use the complete namespaced class to make examples cleaner, but you're encouraged to make use of `use` in all your classes:
123123

124124
```php
125125
use LaravelBook\Ardent\Ardent;
@@ -135,22 +135,15 @@ class User extends Ardent {}
135135
Ardent models use Laravel's built-in [Validator class](http://doc.laravelbook.com/validation/). Defining validation rules for a model is simple and is typically done in your model class as a static variable:
136136

137137
```php
138-
use LaravelBook\Ardent\Ardent;
139-
140-
class User extends Ardent {
138+
class User extends \LaravelBook\Ardent\Ardent {
141139

142-
/**
143-
* Ardent validation rules
144-
*/
145140
public static $rules = array(
146-
'name' => 'required|between:4,16',
147-
'email' => 'required|email',
148-
'password' => 'required|alpha_num|between:4,8|confirmed',
141+
'name' => 'required|between:4,16',
142+
'email' => 'required|email',
143+
'password' => 'required|alpha_num|between:4,8|confirmed',
149144
'password_confirmation' => 'required|alpha_num|between:4,8',
150145
);
151146

152-
...
153-
154147
}
155148
```
156149

@@ -159,10 +152,11 @@ class User extends Ardent {
159152
Ardent models validate themselves automatically when `Ardent->save()` is called.
160153

161154
```php
162-
$user = new User;
163-
$user->name = 'John doe';
164-
$user->email = '[email protected]';
155+
$user = new User;
156+
$user->name = 'John doe';
157+
$user->email = '[email protected]';
165158
$user->password = 'test';
159+
166160
$success = $user->save(); // returns false if model is invalid
167161
```
168162

@@ -190,12 +184,12 @@ There are two ways to override Ardent's validation:
190184
#### 2. Override Rules and Messages
191185
both `Ardent->save($rules, $customMessages)` and `Ardent->validate($rules, $customMessages)` take two parameters:
192186

193-
- `$rules` is an array of Validator rules of the same form as `Ardent::rules`.
194-
- The same is true of the `$customMessages` parameter (same as `Ardent::customMessages`)
187+
- `$rules` is an array of Validator rules of the same form as `Ardent::$rules`.
188+
- The same is true of the `$customMessages` parameter (same as `Ardent::$customMessages`)
195189

196190
An array that is **not empty** will override the rules or custom error messages specified by the class for that instance of the method only.
197191

198-
> **Note:** the default value for `$rules` and `$customMessages` is empty `array()`, if you pass an `array()` nothing will be overriden.
192+
> **Note:** the default value for `$rules` and `$customMessages` is empty `array()`; thus, if you pass an `array()` nothing will be overriden.
199193
200194
<a name="modelhooks"></a>
201195
## Model Hooks
@@ -255,19 +249,13 @@ $user->save(array(), array(),
255249
Just like the Laravel Validator, Ardent lets you set custom error messages using the [same sytax](http://doc.laravelbook.com/validation/#custom-error-messages).
256250

257251
```php
258-
use LaravelBook\Ardent\Ardent;
259-
260-
class User extends Ardent {
252+
class User extends \LaravelBook\Ardent\Ardent {
261253

262-
/**
263-
* Ardent Messages
264-
*/
265254
public static $customMessages = array(
266-
'required' => 'The :attribute field is required.'
255+
'required' => 'The :attribute field is required.',
256+
...
267257
);
268258

269-
...
270-
271259
}
272260
```
273261

@@ -284,9 +272,9 @@ Ardent is capable of hydrating your entity model class from the form input submi
284272
Let's see it action. Consider this snippet of code:
285273

286274
```php
287-
$user = new User;
288-
$user->name = Input::get('name');
289-
$user->email = Input::get('email');
275+
$user = new User;
276+
$user->name = Input::get('name');
277+
$user->email = Input::get('email');
290278
$user->password = Hash::make(Input::get('password'));
291279
$user->save();
292280
```
@@ -305,9 +293,7 @@ Believe it or not, the code above performs essentially the same task as its olde
305293
To enable the auto-hydration feature, simply set the `$autoHydrateEntityFromInput` instance variable to `true` in your model class:
306294

307295
```php
308-
use LaravelBook\Ardent\Ardent;
309-
310-
class User extends Ardent {
296+
class User extends \LaravelBook\Ardent\Ardent {
311297

312298
public $autoHydrateEntityFromInput = true;
313299

@@ -322,9 +308,7 @@ Ardent models can *auto-magically* purge redundant input data (such as *password
322308
To enable this feature, simply set the `$autoPurgeRedundantAttributes` instance variable to `true` in your model class:
323309

324310
```php
325-
use LaravelBook\Ardent\Ardent;
326-
327-
class User extends Ardent {
311+
class User extends \LaravelBook\Ardent\Ardent {
328312

329313
public $autoPurgeRedundantAttributes = true;
330314

@@ -339,11 +323,9 @@ Suppose you have an attribute named `password` in your model class, but don't wa
339323
To do that, add the attribute name to the `Ardent::$passwordAttributes` static array variable in your model class, and set the `$autoHashPasswordAttributes` instance variable to `true`:
340324

341325
```php
342-
use LaravelBook\Ardent\Ardent;
343-
344-
class User extends Ardent {
326+
class User extends \LaravelBook\Ardent\Ardent {
345327

346-
public static $passwordAttributes = array('password');
328+
public static $passwordAttributes = array('password');
347329

348330
public $autoHashPasswordAttributes = true;
349331

0 commit comments

Comments
 (0)