Пример #1
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;
         }
     }
 }
Пример #2
0
 public function search(Request $request)
 {
     $searchTerm = $request->input('q');
     $games = Game::where('name', 'like', "%{$searchTerm}%")->paginate(15);
     //return view('site.search', ['games' => $gameSearch, 'searchTerm' => $searchInput]);
     return view('site.search', compact('games', 'searchTerm'));
 }
Пример #3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $game = \Pcmrcritic\Entities\Game::findorfail($id);
     return view('game.game', ['game' => $game]);
 }