The "unique" and "exists" rules use the DatabasePresenceVerifier class. That way, you donβt really need to extend the unique rule, just access this presence verifier. For instance:
Validator::extend('encrypted_unique', function ($attribute, $value, $parameters, $validator) { list ($table, $column, $ignore_id) = $parameters; // or hard-coded if fixed $count = $validator->getPresenceVerifier()->getCount($table, $column, encrypt($value), $ignore_id); return $count === 0; });
Then you can use it as usual:
'identifier' => "encrypted_unique:table,column,$this_id"
source share