PaperQuestion.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class PaperQuestion extends Model
  5. {
  6. protected $table = 'paper_questions';
  7. protected $primaryKey = 'id';
  8. protected $fillable = [
  9. 'paper_id',
  10. 'question_id',
  11. 'question_bank_id',
  12. 'knowledge_point',
  13. 'question_type', // choice-选择题, fill-填空题, answer-解答题
  14. 'question_text',
  15. 'difficulty',
  16. 'score',
  17. 'estimated_time',
  18. 'question_number',
  19. 'student_answer',
  20. 'is_correct',
  21. 'score_obtained',
  22. ];
  23. protected $casts = [
  24. 'paper_id' => 'string',
  25. 'question_id' => 'string',
  26. 'question_bank_id' => 'integer',
  27. 'question_type' => 'string',
  28. 'question_text' => 'string',
  29. 'difficulty' => 'float',
  30. 'score' => 'float',
  31. 'estimated_time' => 'integer',
  32. 'question_number' => 'integer',
  33. 'is_correct' => 'boolean',
  34. 'score_obtained' => 'float',
  35. 'created_at' => 'datetime',
  36. 'updated_at' => 'datetime',
  37. ];
  38. /**
  39. * 获取所属试卷
  40. */
  41. public function paper()
  42. {
  43. return $this->belongsTo(Paper::class, 'paper_id', 'paper_id');
  44. }
  45. /**
  46. * 获取对应的题库题目
  47. */
  48. public function questionBank()
  49. {
  50. return $this->belongsTo(\App\Models\Question::class, 'question_bank_id', 'id');
  51. }
  52. /**
  53. * 按 question_id 查询题目的作用域
  54. */
  55. public function scopeByQuestionId($query, $questionId)
  56. {
  57. return $query->where('question_id', $questionId);
  58. }
  59. /**
  60. * 按 question_bank_id 查询题目的作用域
  61. */
  62. public function scopeByQuestionBankId($query, $questionBankId)
  63. {
  64. return $query->where('question_bank_id', $questionBankId);
  65. }
  66. }