avatar->profile_id; } /** * Get the middleware the job should pass through. * * @return array */ public function middleware(): array { return [(new WithoutOverlapping("avatar-storage-purge:{$this->avatar->profile_id}"))->shared()->dontRelease()]; } /** * Create a new job instance. */ public function __construct(Avatar $avatar) { $this->avatar = $avatar->withoutRelations(); } /** * Execute the job. */ public function handle(): void { $avatar = $this->avatar; $disk = AvatarService::disk(); $files = collect(AvatarService::storage($avatar)); $curFile = Str::of($avatar->cdn_url)->explode('/')->last(); $files = $files->filter(function($f) use($curFile) { return !$curFile || !str_ends_with($f, $curFile); })->each(function($name) use($disk) { $disk->delete($name); }); return; } }