Laravel: validation for unique username issue

Posted by T2theC on Stack Overflow See other posts from Stack Overflow or by T2theC
Published on 2014-08-22T15:20:52Z Indexed on 2014/08/22 16:21 UTC
Read the original article Hit count: 219

Filed under:
|
|
|
|

I have a noodle scratcher that I can't seem to figure out. I am validating for unique usernames and emails addresses. I have the following rules:

protected $rules = array(
    'username' => 'required|min:4|unique:users,username',
    'email'    => 'email|unique:users,email',
    'password' => 'min:6',
);

If I update a form that has the username (which is the same as it currently is), I get a The username has already been taken. error. If I do the same with the email, I get no error at all.

I know about adding the last param to the unique validation:

'unique:users,username,{{$id}}' or 'unique:users,username,'.$id

This doesn't work on the username. I get the same issue.

I can't figure out why this works for the email, but not the username.

Anyone had a similar issue or know where I am going wrong?

Many thanks,

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql