feat: some fixes to the ui, imlemented user and guest user, ans used the dahboard

This commit is contained in:
2026-08-16 16:24:25 +02:00
parent 4639baa9ae
commit 50e9fbd0b0
37 changed files with 1657 additions and 194 deletions
+48 -2
View File
@@ -7,6 +7,7 @@ use App\Models\Room;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class JoinRoomRequest extends FormRequest
{
@@ -37,9 +38,54 @@ class JoinRoomRequest extends FormRequest
->where('join_code', $this->input('join_code'))
->value('id');
$existingPlayerId = null;
if ($roomId !== null && $this->user() !== null) {
$existingPlayerId = Player::query()
->where('room_id', $roomId)
->where('user_id', $this->user()->id)
->value('id');
} elseif ($roomId !== null) {
$sessionPlayerId = $this->session()->get("room_players.{$roomId}");
$existingPlayerId = is_numeric($sessionPlayerId)
? Player::query()
->where('room_id', $roomId)
->whereKey((int) $sessionPlayerId)
->value('id')
: null;
}
$playerNameRules = ['required', 'string', 'max:50'];
if ($existingPlayerId === null) {
$playerNameRules[] = Rule::unique(Player::class, 'name')->where('room_id', $roomId);
}
return [
'join_code' => ['bail', 'string', 'required', 'size:6', Rule::exists(Room::class, 'join_code')],
'player_name' => ['required', 'string', 'max:50', Rule::unique(Player::class, 'name')->where('room_id', $roomId)],
'join_code' => [
'bail',
'string',
'required',
'size:6',
Rule::exists(Room::class, 'join_code')->whereNull('deleted_at'),
],
'player_name' => $playerNameRules,
];
}
/** @return array<callable(Validator): void> */
public function after(): array
{
return [
function (Validator $validator): void {
$room = Room::query()
->where('join_code', $this->input('join_code'))
->first();
if ($room?->isClosed()) {
$validator->errors()->add('join_code', 'Dieser Raum ist geschlossen.');
}
},
];
}