Added quiz features
This commit is contained in:
47
app/Models/PvpMatch.php
Normal file
47
app/Models/PvpMatch.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user