build the backend structure and the fe for the Game

This commit is contained in:
2026-08-15 22:37:53 +02:00
parent c5fd3f9d79
commit 4340ca9e12
37 changed files with 1611 additions and 56 deletions
+48 -2
View File
@@ -2,9 +2,55 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\SubmitVoteRequest;
use App\Models\Player;
use App\Models\Room;
use App\Models\Vote;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
class VoteController extends Controller
{
//
public function store(
SubmitVoteRequest $request,
Room $room,
): RedirectResponse {
$player = $request->attributes->get('currentPlayer');
abort_unless(
$player instanceof Player
&& $player->room_id === $room->id,
403,
);
$value = $request->validated('value');
DB::transaction(function () use ($room, $player, $value) {
$lockedRoom = Room::query()
->lockForUpdate()
->findOrFail($room->id);
if ($lockedRoom->revealed_at !== null) {
throw ValidationException::withMessages([
'value' => 'Die Karten wurden bereits aufgedeckt.',
]);
}
Vote::updateOrCreate(
[
'room_id' => $lockedRoom->id,
'player_id' => $player->id,
'round' => $lockedRoom->current_round,
],
[
'value' => $value,
],
);
$lockedRoom->increment('state_version');
});
return back();
}
}