i'm trying to create back end UI of my website. User with admin access can login into the admin section and then edit registered users details.
i have a script which displays list of all registered users. When admin clicks on the name of a particular user, the details of that user is displayed in a form. The inputs of form contains previously stored values.
Now, what i want is if admin wants to change the email or username of that user, the new values should be unique. SO i added validation rule of unique in the validation rules of email and username.
$rules = array(
'name'=>'min:2',
'email'=>'email|unique:users',
'username'=>'min:5|unique:users',
'password'=>'min:5',
'cpassword'=>'required_with:password|same:password'
);
Now if the admin wants to change the name, then the form doesn't processes forward and gives an error that username and email should be unique because this is what i have written in the rules.
Then i created a hidden field(named id) in the form, which contained id of that particular user. I checked the value of the id by echoing $id = Input::get('id') and it displayed id of that particular user.
i tried to use this id in the rules:
$rules = array(
'name'=>'min:2',
'email'=>'email|unique:users,email,$id',
'username'=>'min:5|unique:users,username,$id',
'password'=>'min:5',
'cpassword'=>'required_with:password|same:password'
);
But still I'm getting errors on form submission that email and username should be unique. Why is it still showing error when i have already mentioned to ignore the user's id while checking uniqueness?