Files
law-api/app/Models/PvpMatch.php
2026-08-08 17:44:09 +03:30

48 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PvpMatch extends Model
{
use HasFactory;
protected $fillable = [
'status',
'started_at',
'ended_at',
'winner_id',
];
protected $casts = [
'started_at' => 'datetime',
'ended_at' => 'datetime',
];
// The two players in this match
public function players()
{
return $this->hasMany(PvpMatchPlayer::class, 'pvp_match_id');
}
// All answers submitted in this match
public function answers()
{
return $this->hasMany(PvpMatchAnswer::class, 'pvp_match_id');
}
// The 5 random questions assigned to this match via pivot table
public function questions()
{
return $this->belongsToMany(Question::class, 'pvp_match_questions', 'pvp_match_id', 'question_id');
}
// The user who won
public function winner()
{
return $this->belongsTo(User::class, 'winner_id');
}
}