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');
|
||||
}
|
||||
}
|
||||
47
app/Models/PvpMatchAnswer.php
Normal file
47
app/Models/PvpMatchAnswer.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PvpMatchAnswer extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'pvp_match_id',
|
||||
'user_id',
|
||||
'question_id',
|
||||
'selected_option_id',
|
||||
'is_correct',
|
||||
'time_taken',
|
||||
'points_earned',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_correct' => 'boolean',
|
||||
'time_taken' => 'float',
|
||||
'points_earned' => 'float',
|
||||
];
|
||||
|
||||
public function match()
|
||||
{
|
||||
return $this->belongsTo(PvpMatch::class, 'pvp_match_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function question()
|
||||
{
|
||||
return $this->belongsTo(Question::class, 'question_id');
|
||||
}
|
||||
|
||||
public function selectedOption()
|
||||
{
|
||||
return $this->belongsTo(QuestionOption::class, 'selected_option_id');
|
||||
}
|
||||
}
|
||||
31
app/Models/PvpMatchPlayer.php
Normal file
31
app/Models/PvpMatchPlayer.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PvpMatchPlayer extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'pvp_match_id',
|
||||
'user_id',
|
||||
'score',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'score' => 'float',
|
||||
];
|
||||
|
||||
public function match()
|
||||
{
|
||||
return $this->belongsTo(PvpMatch::class, 'pvp_match_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user