I’m validating that the social security number is unique in the database before I submit. I need to assure that all numbers submitted are unique EXCEPT if the user submits 999999999. I’m using ActiveRecord and regular validation rules() so accomplish this, but it’s not working as I expect it to.
In my validation rules I have this:
['ssn', 'unique', 'targetAttribute' => ['ssn'], 'message' => 'Social security number already exists in the database.', 'filter' => function ($query) { $query->where(['not', ['ssn' => '999999999']]); }],
With this code, it does flag a number as unique. However, it does not exclude the 999999999 number from the check.