123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace App\Services\Course;
- use App\Repositories\Criteria\Course\CategoryCriteria;
- use App\Repositories\Eloquent\Course\CategoryRepositoryEloquent;
- use App\Repositories\Presenters\Course\CategoryPresenter;
- use Illuminate\Http\Request;
- class CategoryService
- {
- /**
- * @var CategoryRepositoryEloquent
- */
- private $categoryRepository;
- /**
- * CategoryService constructor.
- *
- * @param CategoryRepositoryEloquent $categoryRepositoryEloquent
- */
- public function __construct(CategoryRepositoryEloquent $categoryRepositoryEloquent)
- {
- $this->categoryRepository = $categoryRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->categoryRepository->pushCriteria(new CategoryCriteria($request));
- $this->categoryRepository->setPresenter(CategoryPresenter::class);
- return $this->categoryRepository->searchCategoryByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->categoryRepository->setPresenter(CategoryPresenter::class);
- return $this->categoryRepository->searchCategoryBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $category = $this->categoryRepository->create($data);
- return $category;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $category = $this->categoryRepository->update($data, $data['id']);
- return $category;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->categoryRepository->delete($id);
- }
- /**
- * 批量删除
- * @param $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->categoryRepository->whereIn('id', $ids)->delete();
- }
- /**
- * 选项
- * @param Request $request
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleSelectOptions(Request $request)
- {
- $this->categoryRepository->pushCriteria(new CategoryCriteria($request));
- return $this->categoryRepository->all(['id', 'name', 'parent_id']);
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request, $f = ['*'])
- {
- $this->categoryRepository->pushCriteria(new CategoryCriteria($request));
- $this->categoryRepository->setPresenter(CategoryPresenter::class);
- return $this->categoryRepository->get($f);
- }
- }
|