MedicalCalculatorQuestion.php 664 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. class MedicalCalculatorQuestion extends Model
  5. {
  6. protected $fillable = [
  7. 'medical_calculator_id', 'question', 'type', 'options', 'score', 'variable'
  8. ];
  9. protected $casts = [
  10. 'options' => 'array',
  11. ];
  12. public function calculator()
  13. {
  14. return $this->belongsTo(MedicalCalculator::class, 'medical_calculator_id');
  15. }
  16. public function getTypeTextAttribute()
  17. {
  18. $types = [
  19. 'text' => '填空',
  20. 'radio' => '单选',
  21. 'checkbox' => '多选'
  22. ];
  23. return $types[$this->type] ?? '未知';
  24. }
  25. }