37 lines
761 B
PHP
37 lines
761 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Answer extends Model
|
|
{
|
|
protected $fillable = [
|
|
'quiz_attempt_id',
|
|
'question_id',
|
|
'selected_option_id',
|
|
'is_correct',
|
|
'time_spent_seconds',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_correct' => 'boolean',
|
|
];
|
|
|
|
public function attempt(): BelongsTo
|
|
{
|
|
return $this->belongsTo(QuizAttempt::class, 'quiz_attempt_id');
|
|
}
|
|
|
|
public function question(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Question::class);
|
|
}
|
|
|
|
public function selectedOption(): BelongsTo
|
|
{
|
|
return $this->belongsTo(QuestionOption::class, 'selected_option_id');
|
|
}
|
|
}
|