ldc-gen-game-web/app/Http/Controllers/Bo/ParticipationController.php
2026-10-20 12:27:49 +02:00

90 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Models\Participation;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
class ParticipationController extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
$this->authorizeResource(Participation::class);
}
/**
* View all winners
*/
public function viewWinnerList(): View
{
$this->authorize('viewWinnerList', Participation::class);
/** @var Builder $participationModels */
$participationModels = Participation::query()
->with(['customer', 'code', 'instantWin', 'product'])
->whereHas('instantWin');
/** Sort columns with a query */
$this->sortQuery($participationModels);
/** Custom pagination */
$participationModels = $this->paginate($participationModels);
/** @var view-string $view */
$view = 'back::pages.winners-list.index';
return view($view, ['participationModels' => $participationModels]);
}
/**
* Display participation form
*/
public function setComment(Participation $participation): View
{
$this->authorize('setComment', $participation);
/** @var view-string $view */
$view = 'back::pages.winners-list.set-comment';
return view($view, [
'participationModel' => $participation,
]);
}
/**
* Set Comment
*/
public function setCommentSubmit(Participation $participation): RedirectResponse
{
$this->authorize('setComment', $participation);
$participation->comment = request()->string('comment')->toString();
$participation->saveOrFail();
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();
return back()->with('success', \trans(
'Le lot est bien marqué comme envoyé et une notification à été envoyé au gagant'
));
}
}