特定ID例外laravel 5.4 / 5.5

时间:2018-12-14 06:36:01

标签: laravel

我正在开发一种功能,如果比赛距离开始只有1分钟,则只有ID号为3的用户才能下注,这是成功的,但是现在不允许状态为“打开”的比赛下注。这是代码:

public function *addMatchBet*(Request $request){
    $rules = [
    'matchid' => 'required|integer|exists:matches,id',
    'teamid' => 'required|integer|exists:teams,id',
    'bet_amount' => 'required|integer|min:100'
    ];
    $validation = \**Validator**::make($request->all(), $rules);
    if ($validation->passes()) {
        $user = \**Auth**::user();
        $match = \App\**Match**::find($request->matchid);
        $team = \App\**Team**::find($request->teamid);

        if(!in_array($team->id, [$match->team_a, $match->team_b])) {
            return [
            'success' => false,
            'errors' => [
            'bet' => ['Match teams have been updated! Please refresh
            page and try again.']
            ]
            ];
        }
        if($match && $match->status == 'open') {
            $betCount = $user->bets
            ->where('match_id', $request->matchid)
            ->count();

            if($match->isClosing(0)) {
                return [
                'success' => false,
                'errors' => [
                'bet' => ['Could no longer bet. This match is now
                starting!']
                ]
                ];
            }

        }

    }
}

有任何想法吗? TYIA

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,这是代码:

  if($match && $match->isClosing(0)) {

                        if($user->id == 3){
                            $betCount = $user->bets
                    ->where('match_id', $request->matchid)
                    ->count();
                        }
                    else{
                        return [
                            'success' => false,
                            'errors' => [
                                'bet' => ['Could no longer bet. This match is now starting!']
                            ]
                        ];
                    }
                }