/**
  * Create a new event instance.
  *
  * @return void
  */
 public function __construct($user_id, $game_id)
 {
     $user = \App\Models\User::find($user_id);
     $game_user = \App\Models\Game_User::where('user_id', $user_id)->where('game_id', $game_id)->first();
     $game_user['has_left'] = true;
     $game_user->save();
     $game_users = \App\Models\Game_User::where('game_id', $game_id)->get();
     $cont = 0;
     foreach ($game_users as $game_user) {
         if ($game_user['has_left']) {
             $cont++;
         }
     }
     $user_list = \App\Models\Game_User::where('game_id', $game_id)->get();
     $msg = 'El jugador ' . $user->first_name . ' se ha rendido';
     if ($cont == count($user_list) - 1) {
         $winner = \App\Models\Game_User::where('has_left', '=', false)->where('game_id', $game_id)->first();
         $winner['has_won'] = true;
         $winner->save();
         $winner_name = \App\Models\User::find($winner['user_id']);
         $msg .= ', y El jugador ' . $winner_name->first_name . ' ha ganado';
     }
     $games = \App\Models\Game_User::where('game_id', $game_id)->where('user_id', $user_id)->first();
     if (!$games['has_left']) {
         $letters_user = \App\Models\Letter_User::where('game_id', '=', $game_id)->where('user_id', $user_id)->get(['letter_id']);
         foreach ($letters_user as $key) {
             $user_letters_save = \App\Models\Inventory_Letter_Game::where('game_id', $game_id)->where('letter_id', $key->letter_id)->first();
             $user_letters_save->quantity++;
             $user_letters_save->save();
         }
     }
     $this->data = ['game_id' => $game_id, 'msg' => $msg];
 }
 public static function random_letter($game_id)
 {
     if (self::have_turn($game_id)) {
         return response()->json(['errors' => true, 'msg' => 'NO es su turno.']);
     }
     $user_inventory = \App\Models\Letter_User::where('game_id', $game_id)->where('user_id', Auth::user()->id)->get();
     for ($i = 0; $i < 4; $i++) {
         $letter = $user_inventory->random();
         $letter_returned = \App\Models\Inventory_Letter_Game::where('letter_id', $letter->letter_id)->where('game_id', $game_id)->first();
         $letter_returned->quantity++;
         $letter_returned->save();
         $letter->delete();
     }
     self::cleanConsTurn($game_id);
     self::turn_pass($game_id);
     self::cleanConsTurn($game_id);
 }