{"action":"created","issue":{"url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/issues/2","repository_url":"https://api.github.com/repos/adonisjs/adonis-validation-provider","labels_url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/issues/2/comments","events_url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/issues/2/events","html_url":"https://github.com/adonisjs/adonis-validation-provider/issues/2","id":166984036,"number":2,"title":"Unique validation rule should support an ignore row clause using a field/value pair","user":{"login":"thetutlage","id":1706381,"avatar_url":"https://avatars.githubusercontent.com/u/1706381?v=3","gravatar_id":"","url":"https://api.github.com/users/thetutlage","html_url":"https://github.com/thetutlage","followers_url":"https://api.github.com/users/thetutlage/followers","following_url":"https://api.github.com/users/thetutlage/following{/other_user}","gists_url":"https://api.github.com/users/thetutlage/gists{/gist_id}","starred_url":"https://api.github.com/users/thetutlage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thetutlage/subscriptions","organizations_url":"https://api.github.com/users/thetutlage/orgs","repos_url":"https://api.github.com/users/thetutlage/repos","events_url":"https://api.github.com/users/thetutlage/events{/privacy}","received_events_url":"https://api.github.com/users/thetutlage/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/labels/feature-request","name":"feature-request","color":"27279b"}],"state":"open","locked":false,"assignee":{"login":"thetutlage","id":1706381,"avatar_url":"https://avatars.githubusercontent.com/u/1706381?v=3","gravatar_id":"","url":"https://api.github.com/users/thetutlage","html_url":"https://github.com/thetutlage","followers_url":"https://api.github.com/users/thetutlage/followers","following_url":"https://api.github.com/users/thetutlage/following{/other_user}","gists_url":"https://api.github.com/users/thetutlage/gists{/gist_id}","starred_url":"https://api.github.com/users/thetutlage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thetutlage/subscriptions","organizations_url":"https://api.github.com/users/thetutlage/orgs","repos_url":"https://api.github.com/users/thetutlage/repos","events_url":"https://api.github.com/users/thetutlage/events{/privacy}","received_events_url":"https://api.github.com/users/thetutlage/received_events","type":"User","site_admin":false},"assignees":[{"login":"thetutlage","id":1706381,"avatar_url":"https://avatars.githubusercontent.com/u/1706381?v=3","gravatar_id":"","url":"https://api.github.com/users/thetutlage","html_url":"https://github.com/thetutlage","followers_url":"https://api.github.com/users/thetutlage/followers","following_url":"https://api.github.com/users/thetutlage/following{/other_user}","gists_url":"https://api.github.com/users/thetutlage/gists{/gist_id}","starred_url":"https://api.github.com/users/thetutlage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thetutlage/subscriptions","organizations_url":"https://api.github.com/users/thetutlage/orgs","repos_url":"https://api.github.com/users/thetutlage/repos","events_url":"https://api.github.com/users/thetutlage/events{/privacy}","received_events_url":"https://api.github.com/users/thetutlage/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2016-07-22T07:11:53Z","updated_at":"2016-09-08T15:31:03Z","closed_at":null,"body":"Unique validation rule must support a field/value pair to ignore a row when doing the validation. It will be helpful when trying to update the field.\r\n\r\n## Current Signature\r\n\r\n```javascript\r\nconst rules = {\r\n\temail: 'unique:users,email'\r\n}\r\n```\r\n\r\nNow when trying to update the user with the payload that has the same email address, will cause a unique validation failure, since this email has already been taken.\r\n\r\nWhat we need is a way to ignore the current user by accepting another parameter that will have add the ignore clause to the unique validation.\r\n\r\n## New Signature\r\n\r\nHere `id,1` is a way to tell the unique validator, to ignore the row where `id=1`\r\n\r\n```javascript\r\nconst rules = {\r\n\temail: 'unique:users,email,id,1'\r\n}\r\n```\r\n\r\n## Usage when updating logged in user profile\r\n\r\nWhen trying to update profile of a logged in user, you are likely going to have the logged in user id.\r\n\r\n#### app/Model/User\r\n```javascript\r\nclass User extends Lucid {\r\n\r\n  static rules (userId) {\r\n     return {\r\n     \temail: `unique:users,email,id,${userId}`\r\n     }\r\n  }\r\n\r\n}\r\n```\r\n\r\nNow when trying to validate the user input, you can fetch the rules like the following example\r\n\r\n#### app/Http/Controllers/UserController\r\n\r\n```javascript\r\nclass UserController {\r\n\r\n  * update (request, response) {\r\n       const rules = User.rules(request.currentUser.id)\r\n       yield Validator.validate(request.all(), rules)\r\n   }\r\n\r\n}\r\n```\r\n\r\n## Note:\r\n\r\nI am open for more suggestions on the same."},"comment":{"url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/issues/comments/245636927","html_url":"https://github.com/adonisjs/adonis-validation-provider/issues/2#issuecomment-245636927","issue_url":"https://api.github.com/repos/adonisjs/adonis-validation-provider/issues/2","id":245636927,"user":{"login":"thetutlage","id":1706381,"avatar_url":"https://avatars.githubusercontent.com/u/1706381?v=3","gravatar_id":"","url":"https://api.github.com/users/thetutlage","html_url":"https://github.com/thetutlage","followers_url":"https://api.github.com/users/thetutlage/followers","following_url":"https://api.github.com/users/thetutlage/following{/other_user}","gists_url":"https://api.github.com/users/thetutlage/gists{/gist_id}","starred_url":"https://api.github.com/users/thetutlage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thetutlage/subscriptions","organizations_url":"https://api.github.com/users/thetutlage/orgs","repos_url":"https://api.github.com/users/thetutlage/repos","events_url":"https://api.github.com/users/thetutlage/events{/privacy}","received_events_url":"https://api.github.com/users/thetutlage/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T15:31:03Z","updated_at":"2016-09-08T15:31:03Z","body":"This is been released a while ago. Closing the issue 😄 "}}
{"actor":{"display_login":"thetutlage"}}