StateService.php 863 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Services;
  3. use App\Repositories\StateRepositoryInterface;
  4. use App\DTO\StateDTO;
  5. use Illuminate\Database\Eloquent\Collection;
  6. use App\Models\State;
  7. class StateService
  8. {
  9. public function __construct(
  10. protected StateRepositoryInterface $repository
  11. ){
  12. }
  13. public function getAllItems(): Collection
  14. {
  15. return $this->repository->all();
  16. }
  17. public function getItem(int $id): ?State
  18. {
  19. return $this->repository->find($id);
  20. }
  21. public function createItem(StateDTO $dto): State
  22. {
  23. return $this->repository->create($dto);
  24. }
  25. public function updateItem(StateDTO $dto, int $id): State
  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. }