コード例 #1
0
 /**
  * @param array $data
  *
  * @return Account
  */
 protected function storeAccount(array $data)
 {
     $type = Config::get('firefly.accountTypeByIdentifier.' . $data['accountType']);
     $accountType = AccountType::whereType($type)->first();
     $newAccount = new Account(['user_id' => $data['user'], 'account_type_id' => $accountType->id, 'name' => $data['name'], 'virtual_balance' => $data['virtualBalance'], 'active' => $data['active'] === true ? true : false, 'iban' => $data['iban']]);
     if (!$newAccount->isValid()) {
         // does the account already exist?
         $searchData = ['user_id' => $data['user'], 'account_type_id' => $accountType->id, 'virtual_balance' => $data['virtualBalance'], 'name' => $data['name'], 'iban' => $data['iban']];
         $existingAccount = Account::firstOrNullEncrypted($searchData);
         if (!$existingAccount) {
             Log::error('Account create error: ' . $newAccount->getErrors()->toJson());
             abort(500);
             // @codeCoverageIgnoreStart
         }
         // @codeCoverageIgnoreEnd
         $newAccount = $existingAccount;
     }
     $newAccount->save();
     return $newAccount;
 }