Paper.php 890 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Repositories\Models\Exam;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Model;
  5. use Prettus\Repository\Contracts\Transformable;
  6. use Prettus\Repository\Traits\TransformableTrait;
  7. /**
  8. * Class Paper.
  9. *
  10. * @package namespace App\Repositories\Models\Exam;
  11. */
  12. class Paper extends Model implements Transformable
  13. {
  14. use TransformableTrait;
  15. protected $table = 'exam_papers';
  16. /**
  17. * The attributes that are mass assignable.
  18. *
  19. * @var array
  20. */
  21. protected $guarded = [];
  22. public function topics()
  23. {
  24. return $this->belongsToMany(Topic::class, 'exam_paper_topic')->orderBy('sort', 'asc');
  25. }
  26. public function getAllotNumsAttribute()
  27. {
  28. return PaperResult::query()->where('paper_id', $this->attributes['id'])->where('status', ModelStatusEnum::OK)->where('is_answer', 0)->count();
  29. }
  30. }