예제 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $companiesJson = File::get(storage_path() . "/app/data/companies.json");
     $companies = json_decode($companiesJson);
     foreach ($companies as $company) {
         Pcmrcritic\Entities\Company::create(array('company' => $company));
     }
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $files = glob(storage_path() . "/app/games/*.json", GLOB_BRACE);
     $companies = Pcmrcritic\Entities\Company::all();
     foreach ($files as $file) {
         $gamesJson = File::get($file);
         $game = json_decode($gamesJson);
         if (!Game::where('steam_appid', '=', $game->steam_appid)->first()) {
             $gameModel = new Game();
             $gameModel->name = $game->name;
             $gameModel->detailed_description = $game->detailed_description;
             $gameModel->required_age = $game->required_age;
             $gameModel->about_the_game = $game->about_the_game;
             $gameModel->supported_languages = isset($game->supported_languages) ? $game->supported_languages : null;
             $gameModel->website = $game->website;
             $gameModel->background = $game->background;
             $gameModel->release_date = $game->release_date->coming_soon ? 'Coming Soon' : ($game->release_date->date != "" ? $game->release_date->date : null);
             $gameModel->steam_appid = (int) $game->steam_appid;
             $gameModel->header_image = $game->header_image;
             $gameModel->fullgame = isset($game->fullgame) ? (int) $game->fullgame->appid : null;
             $gameModel->type = $game->type;
             $gameModel->save();
             if (isset($game->publishers)) {
                 foreach ($game->publishers as $key => $value) {
                     if (trim($value) != "") {
                         $filter = $companies->where('company', trim($value));
                         foreach ($filter as $company) {
                             $publisher = new CompanyGame();
                             $publisher->company_id = $company->id;
                             $publisher->game_id = $gameModel->id;
                             $publisher->type = 'publisher';
                             $publisher->save();
                             $publisher = null;
                         }
                     }
                 }
             }
             if (isset($game->developers)) {
                 foreach ($game->developers as $key => $value) {
                     if (trim($value) != "") {
                         $filter = $companies->where('company', trim($value));
                         foreach ($filter as $company) {
                             $developer = new CompanyGame();
                             $developer->company_id = $company->id;
                             $developer->game_id = $gameModel->id;
                             $developer->type = 'developer';
                             $developer->save();
                             $developer = null;
                         }
                     }
                 }
             }
             $gameModel = null;
         }
     }
 }