openclassify/addons/default/visiosoft/profile-module/src/Profile/Validation/ValidateRegister.php
2020-01-31 12:30:12 +03:00

20 lines
796 B
PHP

<?php namespace Visiosoft\ProfileModule\Profile\Validation;
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
use Visiosoft\ProfileModule\Profile\Contract\ProfileRepositoryInterface;
class ValidateRegister
{
public function handle(FormBuilder $builder, ProfileRepositoryInterface $profileRepository, $attribute, $value)
{
if (!is_numeric($builder->getPostValue('phone'))) {
$builder->addFormError('phone', trans('visiosoft.module.profile::message.error_valid_phone'));
return false;
} elseif (!is_null($profileRepository->findPhoneNumber($builder->getPostValue('phone')))) {
$builder->addFormError('phone', trans('visiosoft.module.profile::message.registered_phone'));
return false;
}
return true;
}
}