| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Paper extends Model
- {
- protected $table = 'papers';
- protected $primaryKey = 'id';
- public $incrementing = true;
- protected $keyType = 'int';
- public $timestamps = true;
-
- const CREATED_AT = 'created_at';
- const UPDATED_AT = 'updated_at';
-
- protected $fillable = [
- 'id',
- 'title',
- 'subject',
- 'total_score',
- 'duration',
- 'difficulty_level',
- 'created_by',
- 'analysis_id', // AI分析记录ID
- ];
-
- protected $casts = [
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- 'total_score' => 'float',
- 'duration' => 'integer',
- ];
-
- /**
- * 获取试卷的题目列表
- */
- public function questions()
- {
- return $this->hasMany(PaperQuestion::class, 'paper_id', 'id');
- }
- /**
- * 获取试卷创建者
- */
- public function createdByUser()
- {
- return $this->belongsTo(User::class, 'created_by', 'user_id');
- }
- /**
- * 获取关联的学生
- */
- public function student()
- {
- return $this->belongsTo(Student::class, 'student_id', 'student_id');
- }
- /**
- * 获取关联的教师
- */
- public function teacher()
- {
- return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
- }
- }
|