RemoveArchiveS3.php 661 B

12345678910111213141516171819202122232425262728
  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. $success = Storage::delete($path);
  16. if ($success) {
  17. return true;
  18. } else {
  19. throw new Exception('Deletion was not possible');
  20. }
  21. } else {
  22. throw new Exception('File not found');
  23. }
  24. }
  25. }