CountryService.php 883 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Services;
  3. use App\Repositories\CountryRepositoryInterface;
  4. use App\DTO\CountryDTO;
  5. use Illuminate\Database\Eloquent\Collection;
  6. use App\Models\Country;
  7. class CountryService
  8. {
  9. public function __construct(
  10. protected CountryRepositoryInterface $repository
  11. ){
  12. }
  13. public function getAllItems(): Collection
  14. {
  15. return $this->repository->all();
  16. }
  17. public function getItem(int $id): ?Country
  18. {
  19. return $this->repository->find($id);
  20. }
  21. public function createItem(CountryDTO $dto): Country
  22. {
  23. return $this->repository->create($dto);
  24. }
  25. public function updateItem(CountryDTO $dto, int $id): Country
  26. {
  27. return $this->repository->update($id, $dto, request()->keys());
  28. }
  29. public function deleteItem(int $id): bool
  30. {
  31. return $this->repository->delete($id);
  32. }
  33. }