123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Services\Info;
- use App\Contracts\Repositories\Info\NewsRepository;
- use App\Repositories\Criteria\Info\NewsCriteria;
- use App\Repositories\Eloquent\Info\NewsRepositoryEloquent;
- use App\Repositories\Presenters\Info\NewsPresenter;
- use Illuminate\Http\Request;
- class NewsService
- {
- /**
- * @var NewsRepositoryEloquent
- */
- private $newsRepository;
- /**
- * NewsService constructor.
- *
- * @param NewsRepositoryEloquent $newsRepositoryEloquent
- */
- public function __construct(NewsRepositoryEloquent $newsRepositoryEloquent)
- {
- $this->newsRepository = $newsRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->newsRepository->pushCriteria(new NewsCriteria($request));
- $this->newsRepository->setPresenter(NewsPresenter::class);
- return $this->newsRepository->searchNewssByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->newsRepository->setPresenter(NewsPresenter::class);
- return $this->newsRepository->searchNewsBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $news = $this->newsRepository->create($data);
- return $news;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $news = $this->newsRepository->update($data, $data['id']);
- return $news;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->newsRepository->delete($id);
- }
- }
|