SourcePaper.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. use App\Models\Textbook;
  8. use App\Models\Question;
  9. class SourcePaper extends Model
  10. {
  11. use HasFactory;
  12. protected $fillable = [
  13. 'uuid',
  14. 'source_file_id',
  15. 'order',
  16. 'order_index',
  17. 'paper_code',
  18. 'title',
  19. 'full_title',
  20. 'chapter',
  21. 'subject',
  22. 'grade',
  23. 'term',
  24. 'edition',
  25. 'series_id',
  26. 'textbook_id',
  27. 'source_type',
  28. 'source_year',
  29. 'raw_markdown',
  30. 'detected_metadata',
  31. 'meta',
  32. ];
  33. protected $casts = [
  34. 'detected_metadata' => 'array',
  35. 'meta' => 'array',
  36. 'order' => 'integer',
  37. 'order_index' => 'integer',
  38. 'created_at' => 'datetime',
  39. 'updated_at' => 'datetime',
  40. ];
  41. public function file(): BelongsTo
  42. {
  43. return $this->belongsTo(SourceFile::class, 'source_file_id');
  44. }
  45. public function parts(): HasMany
  46. {
  47. return $this->hasMany(PaperPart::class, 'source_paper_id');
  48. }
  49. public function textbook(): BelongsTo
  50. {
  51. return $this->belongsTo(Textbook::class, 'textbook_id');
  52. }
  53. public function questions(): HasMany
  54. {
  55. return $this->hasMany(Question::class, 'source_paper_id');
  56. }
  57. public function candidates(): HasMany
  58. {
  59. return $this->hasMany(PreQuestionCandidate::class, 'source_paper_id');
  60. }
  61. public function questionRefs(): HasMany
  62. {
  63. return $this->hasMany(PaperQuestionRef::class, 'source_paper_id');
  64. }
  65. public function series(): BelongsTo
  66. {
  67. return $this->belongsTo(TextbookSeries::class, 'series_id');
  68. }
  69. }