jeudi 1 juin 2017

Laravel Validation - Unique Username

I am having problem getting Validation to work properly, currently it is passed when it should not be passed.

Username field (users.username) should be unique based on client_id in the users table. Different client can have same username from other client.

$rule['username'] = Rule::unique('users', 'username')->where(function ($query) {
                         $query->where('client_id', $this->user()->client_id);
                   })->ignore($this->user()->id, 'id');

For example:

User1 and Users2 are belong to client_id = 2

User1 is not allow to change their username to Users2.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire