Skip to content

Commit

Permalink
fix: filter null values before creating hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
purplelemons-dev authored Jul 12, 2022
1 parent 2104e01 commit 79169a6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Contracts/HasSearchableHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 79169a6

Please sign in to comment.