Ejemplo n.º 1
0
 public function createRoom(Request $request)
 {
     $createGame = Game::prepareCreateGame(Input::all());
     $gameCreated = Game::create($createGame);
     $gameCreated->attachPlayersToGame();
     return Redirect::to('gameLobby');
 }
Ejemplo n.º 2
0
 public function createRoom(Request $request)
 {
     $createGame = Game::prepareCreateGame(Input::all());
     if (Game::where('gameName', '=', $createGame['gameName'])->first() != null) {
         return Redirect::to('gameLobby')->with('message', 'Game Already Exists!');
     }
     $user = Auth::user()->id;
     $gameCreated = Game::create($createGame);
     $gameCreated->attachPlayersToGame();
     $player = User::findOrFail($user);
     $relation = $player->games->find($gameCreated['game_id']);
     $relation->pivot->isPlayer = 1;
     if ($gameCreated->joinedPlayers == $gameCreated->maxPlayers) {
         $gameCreated->status = "Playing";
     }
     $relation->pivot->save();
     $gameCreated->save();
     return Redirect::to('gameLobby')->with('message', 'Game Created!');
 }