1
0
Fork 0

Update AvatarObserver, add logic to delete avatars stored in S3

This commit is contained in:
Daniel Supernault 2021-01-25 21:37:44 -07:00
parent f7e72d7c62
commit 9eafc31e6f
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 10 additions and 0 deletions

View File

@ -3,6 +3,8 @@
namespace App\Observers; namespace App\Observers;
use App\Avatar; use App\Avatar;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class AvatarObserver class AvatarObserver
{ {
@ -54,6 +56,14 @@ class AvatarObserver
) { ) {
@unlink($path); @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);
}
}
} }
/** /**