RemoveArchiveS3.php 551 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Traits;
  3. use Exception;
  4. use Illuminate\Support\Facades\Storage;
  5. trait RemoveArchiveS3
  6. {
  7. /**
  8. * Delete a file and return a boolean if succeded.
  9. *
  10. * @throws \Exception If the file as not found or if the deletion failed.
  11. */
  12. public function removeArchiveByPath(string $path): bool
  13. {
  14. if (! Storage::exists($path)) {
  15. return false;
  16. }
  17. if (! Storage::delete($path)) {
  18. throw new Exception('Deletion was not possible');
  19. }
  20. return true;
  21. }
  22. }