public static function boot() { parent::boot(); Account::created(function ($account) { // destiny stuff $data = new Data(); $data->account_id = $account->id; $data->membershipId = $account->destiny_membershipId; $data->save(); // halo 5 stuff $h5_data = new H5Data(); $h5_data->account_id = $account->id; $h5_data->save(); }); }
/** * @param $gamertag * @return Account|void|static * @throws H5PlayerNotFoundException * @throws Helpers\Network\ThreeFourThreeOfflineException */ public function getAccountByGamertag($gamertag) { $url = sprintf(Constants::$servicerecord_arena, Text::encodeGamertagForApi($gamertag)); $account = $this->checkCacheForGamertag($gamertag); if ($account instanceof Account) { // lets check if they have H5 data if (!$account->h5 instanceof Data) { $h5_data = new Data(); $h5_data->account_id = $account->id; $h5_data->save(); } return $account; } $json = $this->getJson($url); if (isset($json['Results'][0]['ResultCode']) && $json['Results'][0]['ResultCode'] == 0) { try { return Account::firstOrCreate(['gamertag' => $json['Results'][0]['Id']]); } catch (QueryException $e) { throw new H5PlayerNotFoundException(); } } else { throw new H5PlayerNotFoundException(); } }