philipbrown/magniloquent — pull request #30 by joshuajabbour (2014-03-18 14:34:53+00:00)
Title: Fix broken logic in excludeFromUniqueChecks

Unfortunately, I think there are a lot of problems with commit 442c19fef3, but as it stands it will horribly break for anyone using more advanced unique rules, due to the code appending the primary key outside of the `if ($count == 1)` conditional.

The current logic only really works if a user has the most simple of unique rules, ones that look like `unique:table`. Therefore, excludeFromUniqueChecks should only alter simpler unique rules (ones where only the table or table/field have been specified). This pull request fixes that problem.

In addition, it adds `$rule_params[] = $this->getKeyName();` when auto-constructing unique rules, in case the model's primary key is something other than `id` (and since the user doesn't have the ability to specify it).

Anyway, those changes should get this into a functional state. My other issues with this are:

* it breaks if the database field name !== the rule field name
* it still provides no solution for using [more complex unique rules](http://laravel.com/docs/validation#rule-unique) with existing models

That's why [my solution](https://github.com/philipbrown/magniloquent/issues/29) required the developer to add a token to their unique rules; that way they were opting in to alteration of their unique rules and had complete control.