mercredi 13 juin 2018

Ignore a unique role with custom key - Laravel - Mongodb

In my project with Laravel 5.6 and MongoDB, to validate my inputs in an update method, I use a validator like below,

  $validator = Validator::make($request->all(), [
            'name' => 'string|max:255',
            'phone' => 'string|valid_phone',
            'email' => ['string', 'email', 'max:255',
                Rule::unique('admins','email')->ignore($id),
            ],
            'password' => 'string|min:6',
            'access' => 'numeric',
        ]);

I want the field to be unique and ignore the same email for the user with special $id.

Everything looks Ok! But when I call my route to update my user and pass the current email of the user as email, It returns a validator error like this,

"email": [
            "The email has already been taken."
        ]

So, the unique validation did not work correctly!

I also have been set the $primaryKey='_id'; in my user model.

What's the problem? Have I missed something?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire