PaperResult.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Repositories\Models\Exam;
  3. use App\Repositories\Models\Base\Admin;
  4. use App\Repositories\Models\Model;
  5. use Prettus\Repository\Contracts\Transformable;
  6. use Prettus\Repository\Traits\TransformableTrait;
  7. /**
  8. * Class PaperResult.
  9. *
  10. * @package namespace App\Repositories\Models\Exam;
  11. */
  12. class PaperResult extends Model implements Transformable
  13. {
  14. use TransformableTrait;
  15. protected $table = 'exam_paper_results';
  16. /**
  17. * The attributes that are mass assignable.
  18. *
  19. * @var array
  20. */
  21. protected $guarded = [];
  22. protected $casts = [
  23. 'result' => 'array',
  24. 'imgs' => 'array'
  25. ];
  26. public function paper()
  27. {
  28. return $this->belongsTo(Paper::class)->select(['id', 'name', 'submit_nums', 'topic_nums', 'mark']);
  29. }
  30. public function assign_admin()
  31. {
  32. return $this->belongsTo(Admin::class)->select(['id', 'username', 'name']);
  33. }
  34. public function polling_admin()
  35. {
  36. return $this->belongsTo(Admin::class)->select(['id', 'username', 'name']);
  37. }
  38. public function getImgUrlsAttribute()
  39. {
  40. $imgs = $this->fromJson($this->attributes['imgs']);
  41. $urls = [];
  42. if (is_array($imgs)) {
  43. foreach ($imgs as $img) {
  44. $urls[] = path_to_url($img);
  45. }
  46. }
  47. return $urls;
  48. }
  49. }