id(); $hasAlreadyParticipated = $customerId ? GoldenCrushGame::hasCustomerParticipated($customerId) : false; return view('club.pages.games.golden-crush', [ 'hasAlreadyParticipated' => $hasAlreadyParticipated, 'videos' => GoldenCrushGame::getVideos(), ]); } /** * Register participation of costumer * * @param Request $request HTTP Request. * @return RedirectResponse Response. */ public function store(Request $request) { $request->validate([ 'choice' => ['required', 'integer', 'in:1,2'], 'rules_accepted' => ['accepted'], ]); $customerId = auth('club')->id(); $alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId); if ($alreadyParticipated) { return back()->with('error', 'Votre vote a déjà été enregistré.'); } GoldenCrushGame::create([ 'customer_id' => $customerId, 'choice' => $request->integer('choice'), 'ip_address' => $request->ip(), ]); return redirect()->route('club.golden-crush.end-of-participation'); } /** * View for end of participation if customer has participated. * @return \Illuminate\Contracts\View\View */ public function endOfParticipation(): \Illuminate\Contracts\View\View { $customerId = auth('club')->id(); $alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId); if (!$alreadyParticipated) { abort(404); } return view('club.pages.games.end-of-participation'); } }