crabideau5691/aware — pull request #4 by cviebrock (2012-03-15 21:05:07+00:00)
Title: Don't set attributes with the same value

In my mind, this should be a feature of Eloquent (and might be in the next version, I'm told).

In the meantime, here was the issue:

```
// in the user model:

$rules = array(
'email' => 'email|unique:users',
);

// in my controller:

$user = User::find($id);
$user->email = 'colin@example.com'; // assume this is the same value as existing
$user->save();
```

This will fail because it's trying to revalidate the email field as unique, and it already exists (duh!).

The "standard" solution is to make the rule `unique:users,email,10` where 10 is the id of the model you're updating. Dynamically changing the rules on each save is a PITA, though.

However (thanks to my last commit!) we are only validating the dirty attributes. All we need to do to solve this is to intercept the __set() method and, if you're trying to set it with the same value as it already has, then silently ignore it. That way, the dirty[] value isn't set, and we don't validate that field.

Tada!