mercredi 8 février 2017

Laravel form validation unique using 2 fields

How can I have a unique validation rule on 2 fields?

a. The application should not allow two people to have the same identical first name and last name.

It is allowed that the users fills in only a first name or only a last name. Because the user may have only one of them.

b. But if the user enters only a first name (Glen), no other person in the table should have the same (first name = 'Glen' and last name = null). another 'Glen Smith' ok.

I tried the following rule. It works great when both fields (first and last name) are not null:

'firstName' => 'unique:people,firstName,NULL,id,lastName,' . $request->lastName

This rule fails on b. when only one field is present.

Any hint?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kHBtzP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire