48 lines
983 B
PHP
48 lines
983 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Quiz extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'category_id',
|
|
'title',
|
|
'slug',
|
|
'year',
|
|
'type',
|
|
'duration_minutes',
|
|
'has_negative_score',
|
|
'is_free',
|
|
'is_published',
|
|
'description',
|
|
];
|
|
|
|
protected $casts = [
|
|
'year' => 'integer',
|
|
'duration_minutes' => 'integer',
|
|
'has_negative_score' => 'boolean',
|
|
'is_free' => 'boolean',
|
|
'is_published' => 'boolean',
|
|
];
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(QuizCategory::class, 'category_id');
|
|
}
|
|
|
|
public function questions()
|
|
{
|
|
return $this->hasMany(Question::class, 'quiz_id')->orderBy('order');
|
|
}
|
|
|
|
public function attempts()
|
|
{
|
|
return $this->hasMany(UserQuizAttempt::class, 'quiz_id');
|
|
}
|
|
}
|