From 7d41c582fbe0951f4b5bdbd4af82d9c54a5022d8 Mon Sep 17 00:00:00 2001 From: Amy Westlake Date: Thu, 31 Jul 2025 10:09:08 +0100 Subject: [PATCH] add string replace to make searching flexible for spaces and hyphens --- src/Components/Modals/CuratorPanel.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Components/Modals/CuratorPanel.php b/src/Components/Modals/CuratorPanel.php index e5964df..7772572 100644 --- a/src/Components/Modals/CuratorPanel.php +++ b/src/Components/Modals/CuratorPanel.php @@ -305,16 +305,18 @@ public function removeFromFiles(int | string $id): void public function updatedSearch(): void { + $flexibleSearch = str_replace([' ', '-', '_'], '%', $this->search); + $this->files = $this->mediaClass ->query() ->when($this->isLimitedToDirectory, function ($query) { return $query->where('directory', $this->directory); }) - ->where('name', 'like', '%' . $this->search . '%') - ->orWhere('title', 'like', '%' . $this->search . '%') - ->orWhere('alt', 'like', '%' . $this->search . '%') - ->orWhere('caption', 'like', '%' . $this->search . '%') - ->orWhere('description', 'like', '%' . $this->search . '%') + ->where('name', 'like', '%' . $flexibleSearch . '%') + ->orWhere('title', 'like', '%' . $flexibleSearch . '%') + ->orWhere('alt', 'like', '%' . $flexibleSearch . '%') + ->orWhere('caption', 'like', '%' . $flexibleSearch . '%') + ->orWhere('description', 'like', '%' . $flexibleSearch . '%') ->limit(50) ->get() ->toArray();