I have a user model that should have unique email addresses, but I also want them to remain empty if the user does not have email ... I see in docs there is a way to make the rule unique and the exception to id ... but Iβm not sure how to make it valid or empty, but unique if it isnβt, Sorry, it seems that itβs simple, but I canβt come up with an answer.
public static $adminrules = 'email' => 'email|unique:users,email,null,id,email,NOT_EMPTY' );
Edit It is possible that using a rule without required sufficient, because a space or zero will pass validation in these cases. I may have a related error due to which I cannot add more than one empty letter, so I cannot verify this.
public static $adminrules = 'email' => 'email|unique:users' );
source share