| 1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace App\Traits;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Str;
- trait RemoveArchiveS3
- {
- /**
- * Upload a base64 encoded image to S3 and return the URL.
- *
- * @param string $base64Image
- * @param string $s3Folder
- * @return string
- * @throws \Exception
- */
- public function removeArchiveByUrl(string $url): bool
- {
- // Extrair o caminho relativo do S3 da URL completa
- $oldImagePath = parse_url($url, PHP_URL_PATH);
- $oldImagePath = ltrim($oldImagePath, '/'); // remover a barra inicial
- // Excluir a imagem antiga do S3
- if (Storage::disk('s3')->exists($oldImagePath)) {
- Storage::disk('s3')->delete($oldImagePath);
- }
- // Return the URL of the uploaded image
- return true;
- }
- }
|