123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Services\Course;
- use App\Contracts\Repositories\Course\VideoRepository;
- use App\Repositories\Criteria\Course\VideoCriteria;
- use App\Repositories\Eloquent\Course\VideoRepositoryEloquent;
- use App\Repositories\Presenters\Course\VideoPresenter;
- use Illuminate\Http\Request;
- class VideoService
- {
- /**
- * @var VideoRepositoryEloquent
- */
- private $videoRepository;
- /**
- * VideoService constructor.
- *
- * @param VideoRepositoryEloquent $videoRepositoryEloquent
- */
- public function __construct(VideoRepositoryEloquent $videoRepositoryEloquent)
- {
- $this->videoRepository = $videoRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->videoRepository->pushCriteria(new VideoCriteria($request));
- $this->videoRepository->setPresenter(VideoPresenter::class);
- return $this->videoRepository->searchVideosByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->videoRepository->setPresenter(VideoPresenter::class);
- return $this->videoRepository->searchVideoBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $video = $this->videoRepository->create($data);
- return $video;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $video = $this->videoRepository->update($data, $data['id']);
- return $video;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->videoRepository->delete($id);
- }
- /**
- * 选项
- * @param Request $request
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleSelectOptions(Request $request)
- {
- $this->videoRepository->pushCriteria(new VideoCriteria($request));
- return $this->videoRepository->all(['id', 'title']);
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request)
- {
- $this->videoRepository->pushCriteria(new VideoCriteria($request));
- $this->videoRepository->setPresenter(VideoPresenter::class);
- return $this->videoRepository->get();
- }
- /**
- * 批量删除
- * @param $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->videoRepository->whereIn('id', $ids)->delete();
- }
- }
|