migrations and models adjusted

This commit is contained in:
2026-08-15 13:35:46 +02:00
parent 6152a0a122
commit c5fd3f9d79
16 changed files with 157 additions and 459 deletions
+29 -1
View File
@@ -5,7 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use phpDocumentor\Reflection\Types\Boolean;
class Player extends Model
{
@@ -13,12 +13,14 @@ class Player extends Model
'room_id',
'name',
'is_moderator',
'last_seen_at',
];
protected function casts(): array
{
return [
'is_moderator' => 'boolean',
'last_seen_at' => 'datetime',
];
}
@@ -36,4 +38,30 @@ class Player extends Model
{
return $this->belongsTo(User::class);
}
public function currentVote(): ?Vote
{
return $this->votes()
->where('round', $this->room->current_round)
->first();
}
public function hasVoted(): bool
{
return $this->votes()
->where('round', $this->room->current_round)
->exists();
}
public function isModerator(): bool
{
return $this->is_moderator;
}
public function markAsSeen(): void
{
$this->update([
'last_seen_at' => now(),
]);
}
}