Ejemplo n.º 1
0
 protected function createOrUpdate(\stdClass $game, \Morpheus\User $user)
 {
     #try to retrieve a game
     $steamGame = \Morpheus\SteamGame::find($game->appid);
     #if fails, create a new one
     if ($steamGame === null) {
         $steamGame = \Morpheus\SteamGame::create(["appid" => $game->appid, 'name' => $game->name, 'img_icon_url' => $game->img_icon_url, 'img_logo_url' => $game->img_logo_url, 'has_community_visible_stats' => isset($game->has_community_visible_stats) ? true : false]);
         $steamGame->setAttribute($steamGame->getKeyName(), $game->appid);
     } else {
         $steamGame->name = $game->name;
         $steamGame->img_icon_url = $game->img_icon_url;
         $steamGame->img_logo_url = $game->img_logo_url;
         $steamGame->has_community_visible_stats = isset($game->has_community_visible_stats) ? true : false;
         $steamGame->save();
     }
     #sync to user
     $pivot_data = ["playtime_forever" => $game->playtime_forever, "playtime_2weeks" => isset($game->playtime_2weeks) ? $game->playtime_2weeks : 0];
     $steamGame->users()->sync([$user->id => $pivot_data], false);
     return $steamGame;
 }