Skip to content

Commit

Permalink
Fixed Collection support in syncTags function (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
zupolgec authored Nov 17, 2022
1 parent fac02fc commit 88d17ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HasTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ public function detachTag(string | Tag $tag, string | null $type = null): static

public function syncTags(string | array | ArrayAccess $tags): static
{
$tags = Arr::wrap($tags);
if (is_string($tags)) {
$tags = Arr::wrap($tags);
}

$className = static::getTagClassName();

Expand Down
9 changes: 9 additions & 0 deletions tests/HasTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@
});


it('can sync multiple tags from a collection', function () {
$this->testModel->attachTags(collect(['tag1', 'tag2', 'tag3']));

$this->testModel->syncTags(collect(['tag3', 'tag4']));

expect($this->testModel->tags->pluck('name')->toArray())->toEqual(['tag3', 'tag4']);
});


it('can sync tags with different types', function () {
$this->testModel->syncTagsWithType(['tagA1', 'tagA2', 'tagA3'], 'typeA');
$this->testModel->syncTagsWithType(['tagB1', 'tagB2'], 'typeB');
Expand Down

0 comments on commit 88d17ce

Please sign in to comment.