73 lines
2 KiB
PHP
73 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Club;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\GoldenCrushGame;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class GoldenCrushController extends Controller
|
|
{
|
|
/**
|
|
* Show game page
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index(): \Illuminate\Contracts\View\View
|
|
{
|
|
$customerId = auth('club')->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');
|
|
}
|
|
}
|