diff --git a/src/MediaCollections/Commands/CleanCommand.php b/src/MediaCollections/Commands/CleanCommand.php index 79df4a583..4fffd5d13 100644 --- a/src/MediaCollections/Commands/CleanCommand.php +++ b/src/MediaCollections/Commands/CleanCommand.php @@ -186,11 +186,8 @@ protected function deleteOrphanedDirectories(): void if (is_null(config("filesystems.disks.{$diskName}"))) { throw DiskDoesNotExist::create($diskName); } - $mediaClass = config('media-library.media_model'); - $mediaInstance = new $mediaClass(); - $keyName = $mediaInstance->getKeyName(); - $mediaIds = collect($this->mediaRepository->all()->pluck($keyName)->toArray()); + $mediaIds = $this->mediaRepository->allIds(); /** @var array */ $directories = $this->fileSystem->disk($diskName)->directories(); diff --git a/src/MediaCollections/MediaRepository.php b/src/MediaCollections/MediaRepository.php index 01e6c15ab..66ec3662e 100644 --- a/src/MediaCollections/MediaRepository.php +++ b/src/MediaCollections/MediaRepository.php @@ -46,6 +46,11 @@ public function all(): DbCollection return $this->query()->get(); } + public function allIds(): Collection + { + return $this->query()->pluck($this->model->getKeyName()); + } + public function getByModelType(string $modelType): DbCollection { return $this->query()->where('model_type', $modelType)->get();