Skip to content

Commit 002340d

Browse files
authored
Merge pull request #6 from alejandrogq/add_custom_key_attribute
Fix: Initialize string variable with empty string instead of null
2 parents 1d4f38d + d8ebab4 commit 002340d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Traits/BelongsToKnowledgeBase.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
trait BelongsToKnowledgeBase
1515
{
16-
protected ?string $knowledgeBaseKeyAttribute = null;
17-
1816
public static function bootBelongsToKnowledgeBase()
1917
{
2018
static::created(queueable(function (Model $model) {
@@ -40,6 +38,11 @@ public function knowledgeBasePayload(): array
4038
return [];
4139
}
4240

41+
public function knowledgeBaseKeyAttribute(): ?string
42+
{
43+
return null;
44+
}
45+
4346
/**
4447
* @return KnowledgeInsertItem[]
4548
*/
@@ -62,8 +65,8 @@ public function knowledgeInsertItems(): array
6265
$chunk->update(['text' => $text->text]);
6366
}
6467

65-
$key = $this->knowledgeBaseKeyAttribute ? $this->{$this->knowledgeBaseKeyAttribute} : $this->getKey();
66-
68+
$key = $this->knowledgeBaseKeyAttribute() ? $this->{$this->knowledgeBaseKeyAttribute()} : $this->getKey();
69+
6770
$items[] = new KnowledgeInsertItem(
6871
id: $chunk->id,
6972
entity: $text->entity,

0 commit comments

Comments
 (0)