Paper.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Paper extends Model
  5. {
  6. protected $table = 'papers';
  7. protected $primaryKey = 'id';
  8. public $incrementing = true;
  9. protected $keyType = 'int';
  10. public $timestamps = true;
  11. const CREATED_AT = 'created_at';
  12. const UPDATED_AT = 'updated_at';
  13. protected $fillable = [
  14. 'id',
  15. 'title',
  16. 'subject',
  17. 'total_score',
  18. 'duration',
  19. 'difficulty_level',
  20. 'created_by',
  21. 'analysis_id', // AI分析记录ID
  22. ];
  23. protected $casts = [
  24. 'created_at' => 'datetime',
  25. 'updated_at' => 'datetime',
  26. 'total_score' => 'float',
  27. 'duration' => 'integer',
  28. ];
  29. /**
  30. * 获取试卷的题目列表
  31. */
  32. public function questions()
  33. {
  34. return $this->hasMany(PaperQuestion::class, 'paper_id', 'id');
  35. }
  36. /**
  37. * 获取试卷创建者
  38. */
  39. public function createdByUser()
  40. {
  41. return $this->belongsTo(User::class, 'created_by', 'user_id');
  42. }
  43. /**
  44. * 获取关联的学生
  45. */
  46. public function student()
  47. {
  48. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  49. }
  50. /**
  51. * 获取关联的教师
  52. */
  53. public function teacher()
  54. {
  55. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  56. }
  57. }