From 79169a6490266cbd2e558c453cf1f5ce5d208b14 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 12 Jul 2022 17:08:40 +1200 Subject: [PATCH] fix: filter null values before creating hashes --- src/Contracts/HasSearchableHash.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Contracts/HasSearchableHash.php b/src/Contracts/HasSearchableHash.php index a1712e9..7b7a816 100644 --- a/src/Contracts/HasSearchableHash.php +++ b/src/Contracts/HasSearchableHash.php @@ -30,9 +30,13 @@ public static function bootHasSearchableHash(): void protected function generateSearchHashes(): Collection { - return collect($this->searchableHash ?? [])->filter()->mapWithKeys(function ($field) { - return [$field => HashedSearch::create($this->getAttribute($field) ?? '')]; - }); + return collect($this->searchableHash ?? []) + ->filter( + fn($field) => ! blank($this->getAttribute($field)) + ) + ->mapWithKeys( + fn ($field) => [$field => HashedSearch::create($this->getAttribute($field))] + ); } public function scopeSearchHashedField(Builder $builder, string $field, string $clearText)