From cec1aa2811f870d8941b2f87f17b1ed6988a52ba Mon Sep 17 00:00:00 2001 From: Mahmoud Abdelhamid Date: Thu, 25 Jul 2024 17:17:09 +0300 Subject: [PATCH] Fix getFiles query logic to prevent duplicate records by properly nesting conditions --- src/Components/Modals/CuratorPanel.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Components/Modals/CuratorPanel.php b/src/Components/Modals/CuratorPanel.php index bfa083a..dd50849 100644 --- a/src/Components/Modals/CuratorPanel.php +++ b/src/Components/Modals/CuratorPanel.php @@ -204,12 +204,12 @@ public function getFiles(int $page = 0, bool $excludeSelected = false): array return $query->where('directory', $this->directory); }) ->when($this->types, function ($query) { - $types = $this->types; - $query = $query->whereIn('type', $types); - $wildcardTypes = collect($types)->filter(fn ($type) => str_contains($type, '*')); - $wildcardTypes?->map(fn ($type) => $query->orWhere('type', 'LIKE', str_replace('*', '%', $type))); - - return $query; + return $query->where(function($query){ + $types = $this->types; + $query = $query->whereIn('type', $types); + $wildcardTypes = collect($types)->filter(fn ($type) => str_contains($type, '*')); + $wildcardTypes?->map(fn ($type) => $query->orWhere('type', 'LIKE', str_replace('*', '%', $type))); + }); }) ->orderBy('created_at', $this->defaultSort);