48 lines
980 B
PHP
48 lines
980 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class UserQuizAttempt extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'quiz_id',
|
|
'started_at',
|
|
'completed_at',
|
|
'total_score',
|
|
'correct_answers',
|
|
'wrong_answers',
|
|
'unanswered',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'started_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
'total_score' => 'float',
|
|
'correct_answers' => 'integer',
|
|
'wrong_answers' => 'integer',
|
|
'unanswered' => 'integer',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function quiz()
|
|
{
|
|
return $this->belongsTo(Quiz::class, 'quiz_id');
|
|
}
|
|
|
|
public function answers()
|
|
{
|
|
return $this->hasMany(UserQuizAnswer::class, 'attempt_id');
|
|
}
|
|
}
|