ldc-legaulois/app/Http/Controllers/Club/GoldenCrushController.php

90 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2026-04-22 17:49:56 +02:00
<?php
namespace App\Http\Controllers\Club;
use App\Http\Controllers\Controller;
2026-05-05 18:16:24 +02:00
use App\Http\Requests\Club\Games\GoldenCrushParticipateRequest;
2026-04-30 17:26:45 +02:00
use App\Lib\Helpers\GamePeriodHelper;
2026-04-29 17:59:19 +02:00
use App\Models\GoldenCrushGame;
2026-09-25 16:25:31 +02:00
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
2026-04-22 17:49:56 +02:00
class GoldenCrushController extends Controller
{
2026-04-29 17:59:19 +02:00
/**
2026-04-22 17:49:56 +02:00
* Show game page
*/
2026-09-25 16:25:31 +02:00
public function index(): View | RedirectResponse
2026-04-29 17:59:19 +02:00
{
2026-05-05 18:16:24 +02:00
$routeNameForGoldenCrush = GamePeriodHelper::routeName();
2026-04-29 17:59:19 +02:00
$customerId = auth('club')->id();
$hasAlreadyParticipated = $customerId ? GoldenCrushGame::hasCustomerParticipated($customerId) : false;
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.golden-crush', [
2026-09-25 16:25:31 +02:00
'hasAlreadyParticipated' => $hasAlreadyParticipated,
'videos' => GoldenCrushGame::getVideos(),
2026-05-05 18:16:24 +02:00
'routeNameForGoldenCrush' => $routeNameForGoldenCrush,
2026-04-29 17:59:19 +02:00
]);
}
/**
* Register participation of costumer
*
2026-09-25 16:25:31 +02:00
* @param GoldenCrushParticipateRequest $request HTTP Request.
2026-04-29 17:59:19 +02:00
* @return RedirectResponse Response.
*/
2026-05-05 18:16:24 +02:00
public function store(GoldenCrushParticipateRequest $request)
2026-04-29 17:59:19 +02:00
{
$customerId = auth('club')->id();
$alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId);
if ($alreadyParticipated) {
return back()->with('error', 'Votre vote a déjà été enregistré.');
}
2026-05-05 18:16:24 +02:00
if ($request->validated()) {
GoldenCrushGame::create([
'customer_id' => $customerId,
2026-09-25 16:25:31 +02:00
'choice' => $request->integer('choice'),
'ip_address' => app('clientIp'),
2026-05-05 18:16:24 +02:00
]);
}
2026-04-29 17:59:19 +02:00
2026-04-30 17:26:45 +02:00
return redirect()->route('club.golden-crush.thanks-for-participation');
}
/**
* View to thanks if customer has participated.
*/
2026-09-25 16:25:31 +02:00
public function thanksForParticipation(): View
2026-04-30 17:26:45 +02:00
{
2026-05-06 17:11:13 +02:00
$customerId = auth('club')->id();
2026-04-30 17:26:45 +02:00
$alreadyParticipated = GoldenCrushGame::hasCustomerParticipated($customerId);
2026-09-25 16:25:31 +02:00
if (! $alreadyParticipated) {
2026-04-30 17:26:45 +02:00
abort(404);
}
2026-09-25 16:25:31 +02:00
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.thanks-for-participation');
2026-04-29 17:59:19 +02:00
}
/**
* View for end of participation if customer has participated.
*/
2026-09-25 16:25:31 +02:00
public function endOfParticipation(): View
2026-04-22 17:49:56 +02:00
{
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.end-of-participation');
2026-04-22 17:49:56 +02:00
}
2026-04-30 17:26:45 +02:00
/**
* View for end of game.
*/
2026-09-25 16:25:31 +02:00
public function endOfGame(): View
2026-04-30 17:26:45 +02:00
{
2026-05-06 17:11:13 +02:00
return view('club.pages.games.golden-crush.end-of-game');
2026-04-30 17:26:45 +02:00
}
2026-04-22 17:49:56 +02:00
}