id(); $hasAlreadyParticipated = $customerId ? GoldenCrushGame::hasCustomerParticipated($customerId) : false; return view('club.pages.games.golden-crush.golden-crush', [ 'hasAlreadyParticipated' => $hasAlreadyParticipated, 'videos' => GoldenCrushGame::getVideos(), 'routeNameForGoldenCrush' => $routeNameForGoldenCrush, ]); } /** * Register participation of costumer * * @param GoldenCrushParticipateRequest $request HTTP Request. * @return RedirectResponse Response. */ public function store(GoldenCrushParticipateRequest $request) { $customerId = auth('club')->id(); $alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId); if ($alreadyParticipated) { return back()->with('error', 'Votre vote a déjà été enregistré.'); } if ($request->validated()) { GoldenCrushGame::create([ 'customer_id' => $customerId, 'choice' => $request->integer('choice'), 'ip_address' => app('clientIp'), ]); } return redirect()->route('club.golden-crush.thanks-for-participation'); } /** * View to thanks if customer has participated. */ public function thanksForParticipation(): View { $customerId = auth('club')->id(); $alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId); if (! $alreadyParticipated) { abort(404); } return view('club.pages.games.golden-crush.thanks-for-participation'); } /** * View for end of participation if customer has participated. */ public function endOfParticipation(): View { return view('club.pages.games.golden-crush.end-of-participation'); } /** * View for end of game. */ public function endOfGame(): View { return view('club.pages.games.golden-crush.end-of-game'); } }