Update AvatarObserver, add logic to delete avatars stored in S3

pull/2587/head
Daniel Supernault 2021-01-25 21:37:44 -07:00
rodzic f7e72d7c62
commit 9eafc31e6f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 0DEF1C662C9033F7
1 zmienionych plików z 10 dodań i 0 usunięć

Wyświetl plik

@ -3,6 +3,8 @@
namespace App\Observers;
use App\Avatar;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class AvatarObserver
{
@ -54,6 +56,14 @@ class AvatarObserver
) {
@unlink($path);
}
if($avatar->cdn_url) {
$disk = Storage::disk(config('filesystems.cloud'));
$base = Str::startsWith($avatar->media_path, 'cache/avatars/');
if($base && $disk->exists($avatar->media_path)) {
$disk->delete($avatar->media_path);
}
}
}
/**