public function validateForCreate(array $data)
{
// 필수 요소 검사
if (!isset($data['status'], $data['rating'], $data['displayName'])) {
throw new InvalidArgumentException();
}
// email이나 account중 하나는 반드시 있어야 한다.
if (!isset($data['email']) && !isset($data['account'])) {
$e = new InvalidArgumentException();
$e->setMessage('email이나 account중 하나가 반드시 있어야 합니다.');
throw $e;
}
// email, displayName 중복검사
if (isset($data['email'])) {
if ($this->emails()->findByAddress($data['email']) !== null) {
throw new MailAlreadyExistsException();
}
}
// displayName 검사
$this->validateDisplayName($data['displayName']);
// account 검사
if (isset($data['account'])) {
$account = $data['account'];
if (!isset($account['accountId'], $account['provider'], $account['data'], $account['token'])) {
$e = new InvalidArgumentException();
$e->setMessage('account 정보가 올바르지 않습니다.');
throw $e;
}
if ($this->accounts()->where(array_only($account, ['accountId', 'provider']))->first() !== null) {
throw new AccountAlreadyExistsException();
}
}
return true;
}