Skip to content

Commit

Permalink
fix: add ability to forcebly hash a record
Browse files Browse the repository at this point in the history
  • Loading branch information
phpsa authored Oct 13, 2022
1 parent 4f44cd9 commit 4cdd650
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Contracts/HasSearchableHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ public static function bootHasSearchableHash(): void
{
//We need to setup hashes for this
static::saved(function ($model) {
$model->generateSearchHashes()->each(function ($hash, $field) use ($model) {
ModelsHashedSearch::updateOrCreate([
'hash_field' => $field,
'hash_id' => $model->getKey(),
'hash_type' => $model->getMorphClass()
], [
'hash' => $hash,
]);
});
$model->buildSearchHash()
});
}

public function buildSearchHash(): void
{
$this->generateSearchHashes()->each(function ($hash, $field) {
ModelsHashedSearch::updateOrCreate([
'hash_field' => $field,
'hash_id' => $this->getKey(),
'hash_type' => $this->getMorphClass()
], [
'hash' => $hash,
]);
});
}

Expand Down

0 comments on commit 4cdd650

Please sign in to comment.