123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Shop\Provinces\Repositories;
- use Jsdecena\Baserepo\BaseRepository;
- use App\Shop\Countries\Country;
- use App\Shop\Provinces\Exceptions\ProvinceNotFoundException;
- use App\Shop\Provinces\Province;
- use App\Shop\Provinces\Repositories\Interfaces\ProvinceRepositoryInterface;
- use Illuminate\Database\Eloquent\ModelNotFoundException;
- use Illuminate\Database\QueryException;
- use Illuminate\Support\Collection;
- class ProvinceRepository extends BaseRepository implements ProvinceRepositoryInterface
- {
-
- public function __construct(Province $province)
- {
- parent::__construct($province);
- }
-
- public function listProvinces(string $order = 'id', string $sort = 'desc', array $columns = ['*']) : Collection
- {
- return $this->all($columns, $order, $sort);
- }
-
- public function findProvinceById(int $id) : Province
- {
- try {
- return $this->findOneOrFail($id);
- } catch (ModelNotFoundException $e) {
- throw new ProvinceNotFoundException($e->getMessage());
- }
- }
-
- public function updateProvince(array $params) : bool
- {
- try {
- return $this->model->update($params);
- } catch (QueryException $e) {
- throw new ProvinceNotFoundException($e->getMessage());
- }
- }
-
- public function listCities(int $provinceId) : Collection
- {
- return $this->findProvinceById($provinceId)->cities()->get();
- }
-
- public function findCountry() : Country
- {
- return $this->model->country;
- }
- }
|