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
+9 -1
View File
@@ -5,6 +5,13 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $id
* @property int|null $user_id
* @property string $name
* @property array<int, array{key: string, label: string}> $cards
* @property bool $is_system
*/
class Deck extends Model
{
protected $fillable = [
@@ -12,7 +19,7 @@ class Deck extends Model
'cards',
];
protected function casts()
protected function casts(): array
{
return [
'cards' => 'array',
@@ -20,6 +27,7 @@ class Deck extends Model
];
}
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
+15
View File
@@ -5,7 +5,19 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
/**
* @property int $id
* @property string $room_id
* @property int|null $user_id
* @property string $name
* @property bool $is_moderator
* @property Carbon|null $last_seen_at
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read Room $room
*/
class Player extends Model
{
protected $fillable = [
@@ -24,16 +36,19 @@ class Player extends Model
];
}
/** @return BelongsTo<Room, $this> */
public function room(): BelongsTo
{
return $this->belongsTo(Room::class);
}
/** @return HasMany<Vote, $this> */
public function votes(): HasMany
{
return $this->hasMany(Vote::class);
}
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
+40 -4
View File
@@ -2,20 +2,40 @@
namespace App\Models;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property string $id
* @property int|null $owner_id
* @property string|null $title
* @property array{name: string, cards: array<int, array{key: string, label: string}>, id?: int} $deck_config
* @property string $join_code
* @property int $current_round
* @property CarbonImmutable|null $revealed_at
* @property int $state_version
* @property CarbonImmutable|null $last_activity_at
* @property CarbonImmutable|null $closed_at
* @property CarbonImmutable|null $deleted_at
* @property int $players_count
*/
class Room extends Model
{
use HasUuids;
use HasUuids, SoftDeletes;
protected $fillable = [
'owner_id',
'title',
'current_round',
'deck_config',
'revealed_at',
'state_version',
'last_activity_at',
'closed_at',
];
protected function casts(): array
@@ -24,18 +44,21 @@ class Room extends Model
'current_round' => 'integer',
'state_version' => 'integer',
'revealed_at' => 'immutable_datetime',
'last_activity_at' => 'immutable_datetime',
'closed_at' => 'immutable_datetime',
'deck_config' => 'array',
];
}
protected static function booted()
protected static function booted(): void
{
static::creating(function (Room $room) {
$room->join_code ??= static::generateJoinCode();
$room->last_activity_at ??= now();
});
}
private static function generateJoinCode(): string
protected static function generateJoinCode(): string
{
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
@@ -45,20 +68,33 @@ class Room extends Model
for ($i = 0; $i < 6; $i++) {
$code .= $alphabet[random_int(0, strlen($alphabet) - 1)];
}
} while (static::where('join_code', $code)->exists());
} while (static::withTrashed()->where('join_code', $code)->exists());
return $code;
}
/** @return HasMany<Player, $this> */
public function players(): HasMany
{
return $this->hasMany(Player::class);
}
/** @return BelongsTo<User, $this> */
public function owner(): BelongsTo
{
return $this->belongsTo(User::class, 'owner_id');
}
/** @return HasMany<Vote, $this> */
public function votes(): HasMany
{
return $this->hasMany(Vote::class);
}
public function isClosed(): bool
{
return $this->closed_at !== null;
}
}
+8
View File
@@ -49,13 +49,21 @@ class User extends Authenticatable implements PasskeyUser
];
}
/** @return HasMany<Player, $this> */
public function players(): HasMany
{
return $this->hasMany(Player::class);
}
/** @return HasMany<Deck, $this> */
public function decks(): HasMany
{
return $this->hasMany(Deck::class);
}
/** @return HasMany<Room, $this> */
public function ownedRooms(): HasMany
{
return $this->hasMany(Room::class, 'owner_id');
}
}
+12
View File
@@ -4,7 +4,17 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
/**
* @property int $id
* @property int $player_id
* @property string $room_id
* @property int $round
* @property string $value
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
class Vote extends Model
{
protected $fillable = [
@@ -21,11 +31,13 @@ class Vote extends Model
];
}
/** @return BelongsTo<Room, $this> */
public function room(): BelongsTo
{
return $this->belongsTo(Room::class);
}
/** @return BelongsTo<Player, $this> */
public function player(): BelongsTo
{
return $this->belongsTo(Player::class);