Files
scrum-poker-internal/app/Models/Player.php
T

68 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Player extends Model
{
protected $fillable = [
'room_id',
'user_id',
'name',
'is_moderator',
'last_seen_at',
];
protected function casts(): array
{
return [
'is_moderator' => 'boolean',
'last_seen_at' => 'datetime',
];
}
public function room(): BelongsTo
{
return $this->belongsTo(Room::class);
}
public function votes(): HasMany
{
return $this->hasMany(Vote::class);
}
public function user(): BelongsTo
{
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(),
]);
}
}