AttachService.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Services\Course;
  3. use App\Repositories\Criteria\Course\AttachCriteria;
  4. use App\Repositories\Eloquent\Course\AttachRepositoryEloquent;
  5. use App\Repositories\Presenters\Course\AttachPresenter;
  6. use Illuminate\Http\Request;
  7. class AttachService
  8. {
  9. /**
  10. * @var AttachRepositoryEloquent
  11. */
  12. private $attachRepository;
  13. /**
  14. * AttachService constructor.
  15. *
  16. * @param AttachRepositoryEloquent $attachRepositoryEloquent
  17. */
  18. public function __construct(AttachRepositoryEloquent $attachRepositoryEloquent)
  19. {
  20. $this->attachRepository = $attachRepositoryEloquent;
  21. }
  22. /**
  23. * @param Request $request
  24. *
  25. * @return mixed
  26. * @throws \Prettus\Repository\Exceptions\RepositoryException
  27. */
  28. public function handleList(Request $request)
  29. {
  30. $this->attachRepository->pushCriteria(new AttachCriteria($request));
  31. $this->attachRepository->setPresenter(AttachPresenter::class);
  32. return $this->attachRepository->searchAttachsByPage();
  33. }
  34. /**
  35. * @param $id
  36. *
  37. * @return \Illuminate\Database\Eloquent\Model
  38. */
  39. public function handleProfile($id)
  40. {
  41. $this->attachRepository->setPresenter(AttachPresenter::class);
  42. return $this->attachRepository->searchAttachBy($id);
  43. }
  44. /**
  45. * @param array $data
  46. *
  47. * @return mixed
  48. * @throws \Prettus\Validator\Exceptions\ValidatorException
  49. */
  50. public function handleStore($data)
  51. {
  52. $attach = $this->attachRepository->create($data);
  53. return $attach;
  54. }
  55. /**
  56. * @param array $data
  57. *
  58. * @return mixed
  59. * @throws \Prettus\Validator\Exceptions\ValidatorException
  60. */
  61. public function handleUpdate($data)
  62. {
  63. $attach = $this->attachRepository->update($data, $data['id']);
  64. return $attach;
  65. }
  66. /**
  67. * @param Request $request
  68. *
  69. * @return mixed
  70. * @throws \Prettus\Validator\Exceptions\ValidatorException
  71. */
  72. public function handleDelete($id)
  73. {
  74. return $this->attachRepository->delete($id);
  75. }
  76. /**
  77. * 选项
  78. * @param Request $request
  79. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
  80. * @throws \Prettus\Repository\Exceptions\RepositoryException
  81. */
  82. public function handleSelectOptions(Request $request)
  83. {
  84. $this->attachRepository->pushCriteria(new AttachCriteria($request));
  85. return $this->attachRepository->all(['id', 'name']);
  86. }
  87. /**
  88. * @param Request $request
  89. *
  90. * @return mixed
  91. * @throws \Prettus\Repository\Exceptions\RepositoryException
  92. */
  93. public function handleAll(Request $request)
  94. {
  95. $this->attachRepository->pushCriteria(new AttachCriteria($request));
  96. $this->attachRepository->setPresenter(AttachPresenter::class);
  97. return $this->attachRepository->get();
  98. }
  99. }