Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject current database row id on custom validation rule #117

Open
Shingedo opened this issue Jan 29, 2015 · 1 comment
Open

Inject current database row id on custom validation rule #117

Shingedo opened this issue Jan 29, 2015 · 1 comment

Comments

@Shingedo
Copy link

This is kind of a follow up to issue #114 which lead to the fix of the injection of the current database rows id into laravels default unique validation rule. My problem is now, that I have a custom validation rule from another package felixkiss/uniquewith-validator called unique_with. This rule basically tests if the combination of a number of columns is unique, i. e. the combination of foreign_key_1, foreign_key_2 and foreign_key_3

'foreign_key_1' => 'unique_with:table,foreign_key_2,foreign_key_3'

This leads to the exact same issue as with laravels default unique rule when validation happens on updating: Of course the combination already exists. It exists on the model itself.

Thankfully the author of the package has thought about this as well and you append a row id as the last parameter to the rule to ignore it, just like laravels unique rule does it.

'foreign_key_1' => 'unique_with:table,foreign_key_2,foreign_key_3,<own_row_id>'

My problem is just how to achieve this while using the validating trait. The only solution I could come up with until now is adding a new config parameter and a new method that does all specified rules. This would basically be a generalisation of the current injectUniqueIdentifierToRules() and a configuration for it which by default replaces laravels own rule and if someone needs it like I do in this case they can add other rules to inject it into.

Would you be willing to add such an option?

@dwightwatson
Copy link
Owner

Yeah, I'd definitely be open to that functionality. I'm a little swamped at the moment but happy to accept a PR in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants