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'); } }
public function checkWinner($code) { $currentUser = Auth::user(); $currentCode = Keycode::where('code', '=', $code)->first(); $winner = Winner::where('user_id', '=', $currentUser->id)->first(); if (!$winner) { Winner::create(['user_id' => $currentUser->id, 'keycode_id' => $currentCode->id]); return true; } else { return false; } }