/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $tabledetails = Gametables::find($id);
     //retrieve PUT value
     $param = Input::only('tablename', 'operator');
     $rules = array('tablename' => 'required', 'operator' => 'required|exists:acl_users,id');
     //custom error messaging
     $messages = array('operator.exists' => 'Operator doesn\'t exist');
     $validator = Validator::make($param, $rules, $messages);
     if (!empty($tabledetails)) {
         if ($validator->passes()) {
             $update = array('table_name' => $param['tablename'], 'operator_id' => $param['operator']);
             $affectedRows = Gametables::where('id', $id)->update($update);
             $message = 'Roullete Table has been successfully created.';
             return Redirect::action('games.index')->with('success', $message);
         } else {
             $messages = $validator->messages();
             return Redirect::action('games.edit', array($id))->with('error', $messages->all());
         }
     } else {
         $message = 'Cannot find roulette game table.';
         return Redirect::action('games.index')->with('error', $message);
     }
     echo json_encode(Input::all());
 }
 public function start()
 {
     if (ACL::checkUserPermission('roulette.start') == false) {
         return Redirect::action('dashboard');
     }
     if (Auth::user()->isOperator()) {
         $game = Games::where('game_name', 'Roulette')->take(1)->get()->first();
         $table = Gametables::where('operator_id', $this->operator_id)->take(1)->get()->first();
         $players = Playeroperators::with('playerdetails', 'credits')->where('operator_id', $this->operator_id)->get();
         if (!empty($table)) {
             $create_channel = array('channel_id' => Utils::generateRandomString(), 'table_id' => $table->id);
             $channel_id = '';
             $channel = Gamechannel::openchannel()->where('table_id', $table->id)->take(1)->get()->first();
             if (!empty($channel)) {
                 $channel_id = $channel->id;
             } else {
                 $channel_create = Gamechannel::create($create_channel);
                 $channel_id = $channel_create->id;
             }
             $gamedetails = Gamechannel::with('tabledetails.gamedetails', 'tabledetails.operator', 'bets', 'bets.playerdetails')->find($channel_id);
             $totalbets = 0;
             $totalplayers = 0;
             if ($gamedetails->bets != null) {
                 foreach ($gamedetails->bets as $gamebets) {
                     $totalbets += $gamebets->bet_amount;
                     $totalplayers++;
                 }
             }
             $title = Lang::get('Start Game');
             $data = array('title' => $title, 'totalbets' => $totalbets, 'totalplayers' => $totalplayers, 'gamedetails' => $gamedetails, 'players' => $players);
             return View::make('operator/create', $data);
         } else {
             return App::abort(401, 'No Roulette table has been assigned to your account.');
         }
     } else {
         return App::abort(401, 'You are not a operator.');
     }
 }