public function checkCode(Request $request) { $code = $request->input('code'); $currentPeriod = $this->period->checkPeriod(); $user = Auth::User(); $this->validate($request, ['code' => 'required|min:6|alpha_num|unique:keycodes,code,' . $code . ',id,used,1']); if ($this->user->checkIfParticipated($user)) { $this->user->hasParticipated($user); if ($this->validateCode->checkIfCodeIsValid($code)) { $result = $this->validateCode->checkIfCodeIsValid($code); if ($this->winner->checkWinner($code)) { $this->validateCode->changeStateOfCode($result); Mail::send('mails.winner', ['user' => $user], function ($ms) use($user) { $ms->to($user->email, $user->name)->subject('U hebt gewonnen!'); }); $alreadyplayed = false; $win = true; return view('code/result', compact('win', 'alreadyplayed', 'currentPeriod')); } } else { $win = false; $alreadyplayed = false; return view('code/result', compact('win', 'alreadyplayed')); } } else { $win = false; $alreadyplayed = true; return view('code/result', compact('win', 'alreadyplayed')); } }
public function index() { $winners = $this->winner->getWinnersOfPreviousPeriods(); $currentPeriod = $this->period->checkPeriod(); $periods = $this->period->all(); return view('index', compact('winners', 'currentPeriod', 'periods')); }
public function checkIfCodeIsValid($code) { $currentPeriod = $this->period->checkPeriod(); $result = Keycode::where('code', '=', $code)->where('used', '=', '0')->where('period_id', '=', $currentPeriod->id)->first(); if ($result) { return $result; } else { return false; } }
public function periods() { if (Auth::check()) { $periods = Period::all(); $currentPeriod = $this->period->checkPeriod(); $codes = Keycode::all(); return view('admin/periods', compact('currentPeriod', 'periods', 'codes')); } else { return view('errors/404'); } }