do not need login

This commit is contained in:
2026-09-10 16:33:13 +02:00
parent 6ca91f3fe9
commit 2ab95cebdf
12 changed files with 184 additions and 71 deletions
+17 -6
View File
@@ -18,7 +18,7 @@ class ShowEmbeddedRoomRequest extends FormRequest
*/
public function authorize(): bool
{
return $this->user() !== null;
return true;
}
protected function prepareForValidation(): void
@@ -67,17 +67,28 @@ class ShowEmbeddedRoomRequest extends FormRequest
return;
}
if ($room === null || $this->user() === null) {
if ($room === null) {
return;
}
$sessionPlayerId = $this->session()->get("room_players.{$room->id}");
$existingPlayer = is_numeric($sessionPlayerId)
? $room->players()->find((int) $sessionPlayerId)
: null;
if ($existingPlayer === null && $this->user() !== null) {
$existingPlayer = $room->players()
->where('user_id', $this->user()->id)
->first();
}
$nameIsTaken = Player::query()
->where('room_id', $room->id)
->where('name', $this->input('player_name'))
->where(function ($query): void {
$query->whereNull('user_id')
->orWhere('user_id', '!=', $this->user()->id);
})
->when(
$existingPlayer !== null,
fn ($query) => $query->whereKeyNot($existingPlayer->id),
)
->exists();
if ($nameIsTaken) {