PermissionService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Database\Eloquent\Collection;
  4. use App\Repositories\PermissionRepositoryInterface;
  5. use App\DTO\PermissionDTO;
  6. use App\Models\Permission;
  7. class PermissionService
  8. {
  9. public function __construct(
  10. protected PermissionRepositoryInterface $permissionRepository,
  11. ) {
  12. }
  13. public function all(): ?Collection
  14. {
  15. return $this->permissionRepository->all();
  16. }
  17. public function allNoTree(): ?Collection
  18. {
  19. return $this->permissionRepository->allNoTree();
  20. }
  21. public function find(int $id): ?Permission
  22. {
  23. return $this->permissionRepository->find(id: $id);
  24. }
  25. public function findByScope(string $scope): ?Permission
  26. {
  27. return $this->permissionRepository->findByScope(scope: $scope);
  28. }
  29. public function store(PermissionDTO $permissionDTO): Permission
  30. {
  31. return $this->permissionRepository->store(permissionDTO: $permissionDTO);
  32. }
  33. public function update(PermissionDTO $permissionDTO, int $id): ?Permission
  34. {
  35. return $this->permissionRepository->update(id: $id, dto: $permissionDTO, fieldsToUpdate: request()->keys());
  36. }
  37. public function delete(int $id): bool
  38. {
  39. return $this->permissionRepository->delete(id: $id);
  40. }
  41. }