['phone', 'trim'],
['phone_repeat', 'trim'],
['phone', 'required'],
['phone_repeat', 'required'],
['phone', 'string', 'min' => 10],
['phone_repeat', 'compare', 'compareAttribute' => 'phone'],
['phone', 'unique', 'targetClass' => '\app\models\User', 'message' => 'Телефон занят'],
public function validatePhone($attribute, $params)
{
if (!$this->hasErrors()) {
$user = User::findOne(['phone' => $this->$attribute]);
if ($user ) {
$this->addError($attribute, 'Телефон занят');
}
}
['phone', 'validatePhone'],