/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = \Auth::user(); $match = Match::find(\Request::input('match')); $sheet = $user->getPrimarySheet(); return \Response::json(['message' => 'You have already be ton this match!'], 422); // Status code here $this->validate($request, ['match' => 'required', 'team' => 'required', 'amount' => 'required|numeric|between:0,' . $sheet->amount]); $bet = new Bet(); $bet->match_id = \Request::input('match'); $bet->amount = \Request::input('amount'); $bet->user()->associate($user); $bet->match()->associate($match); $bet->sheet()->associate($sheet); $bet->save(); $sheet->amount = $sheet->amount - \Request::input('amount'); $sheet->save(); /*return \Auth::check() ? 'authenticated': "NO biiish!";*/ /*return \Response::json($bet);*/ }
public static function _getUserChanceOfGameByUser($user_id, $game_id, $game_price) { $chance = 0; if (!is_null($user)) { //if(isset(self::$chances_cache[$user->id])) return self::$chances_cache[$user->id]; $bet = Bet::where('game_id', $game_id)->where('user_id', $user_id)->sum('price'); if ($bet) { $chance = round($bet / $game_price, 3) * 100; } //self::$chances_cache[$user->id] = $chance; } return $chance; }