Exemplo n.º 1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     if (Auth::check()) {
         if (Auth::user()->role == 'admin') {
             $games = new GiantBombApi();
             $gamesArray = $games->getAllGameIds();
             $dbGames = \App\Game::all();
             $pluckIdFromApi = array_pluck($gamesArray, 'id');
             $pluckIdFromDb = array_pluck($dbGames, 'id');
             $results = array_diff($pluckIdFromApi, $pluckIdFromDb);
             $gameNames = [];
             foreach ($results as $result) {
                 array_push($gameNames, $games->getGameNameFromApi($result));
             }
             return view('game.create', compact('gameNames'));
         }
     } else {
         return view('errors.unauthorized');
     }
 }