LMS/app/Models/TestAttempt.php

47 lines
953 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class TestAttempt extends Model
{
use HasFactory;
protected $fillable = [
'test_id',
'user_id',
'started_at',
'finished_at',
'score',
'correct_answers',
'total_questions',
'passed',
'feedback',
];
protected $casts = [
'started_at' => 'datetime',
'finished_at' => 'datetime',
'passed' => 'boolean',
];
public function test(): BelongsTo
{
return $this->belongsTo(Test::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function responses(): HasMany
{
return $this->hasMany(TestResponse::class);
}
}