ldc-gen-game-web/app/Http/Controllers/Bo/ParticipationController.php

91 lines
2.4 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-02 12:09:46 +02:00
declare(strict_types=1);
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Models\Participation;
2023-12-05 12:33:25 +01:00
use Illuminate\Contracts\View\View;
2026-10-02 12:09:46 +02:00
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
2023-12-05 12:33:25 +01:00
class ParticipationController extends Controller
{
/**
2023-12-05 12:33:25 +01:00
* Create the controller instance.
*/
public function __construct()
{
$this->authorizeResource(Participation::class);
}
/**
* View all winners
*/
2023-12-05 12:33:25 +01:00
public function viewWinnerList(): View
2021-08-18 17:08:02 +02:00
{
2023-12-05 12:33:25 +01:00
$this->authorize('viewWinnerList', Participation::class);
2026-10-02 12:09:46 +02:00
/** @var Builder $participationModels */
$participationModels = Participation::query()
->with(['customer', 'code', 'instantWin', 'product'])
->whereHas('instantWin');
/** Sort columns with a query */
$this->sortQuery($participationModels);
2021-02-23 18:27:03 +01:00
/** Custom pagination */
2023-11-23 17:31:28 +01:00
$participationModels = $this->paginate($participationModels);
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'back::pages.winners-list.index';
return view($view, ['participationModels' => $participationModels]);
}
2023-12-13 16:47:28 +01:00
/**
* Display participation form
*/
public function setComment(Participation $participation): View
{
$this->authorize('setComment', $participation);
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'back::pages.winners-list.set-comment';
return view($view, [
'participationModel' => $participation,
2023-12-13 16:47:28 +01:00
]);
}
/**
* Set Comment
*/
public function setCommentSubmit(Participation $participation): RedirectResponse
{
$this->authorize('setComment', $participation);
2026-10-02 12:09:46 +02:00
$participation->comment = request()->string('comment')->toString();
2023-12-13 16:47:28 +01:00
$participation->saveOrFail();
2026-10-02 12:09:46 +02:00
2023-12-13 16:47:28 +01:00
return back()->with('success', \trans(
'Le commentaire à bien été mis à jour'
));
}
/**
* Change prize sent
*/
public function changePrizeSent(Participation $participation): RedirectResponse
{
$this->authorize('changePrizeSent', $participation);
$participation->prize_sent = true;
$participation->saveOrFail();
2026-10-02 12:09:46 +02:00
return back()->with('success', \trans(
'Le lot est bien marqué comme envoyé et une notification à été envoyé au gagant'
));
}
}