Skip to content

Commit f9b422e

Browse files
authored
Support pluck() on term query builder (#476)
* Support pluck() on term query builder * Add test coverage
1 parent 8e5633d commit f9b422e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Taxonomies/TermQueryBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ public function get($columns = ['*'])
194194
});
195195
}
196196

197+
public function pluck($column, $key = null)
198+
{
199+
$this->applyCollectionAndTaxonomyWheres();
200+
201+
return parent::pluck($column, $key);
202+
}
203+
197204
public function count()
198205
{
199206
$this->applyCollectionAndTaxonomyWheres();

tests/Terms/TermTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@ public function it_build_stache_associations_when_taxonomy_driver_is_not_eloquen
105105

106106
$this->assertCount(2, $taxonomyStore->store('test')->index('associations')->items());
107107
}
108+
109+
#[Test]
110+
public function it_applies_taxonomy_wheres_using_pluck_count_and_get()
111+
{
112+
$taxonomy = tap(Taxonomy::make('test')->title('test'))->save();
113+
114+
$term = tap(TermFacade::make('test-term')->taxonomy('test')->data([]))->save();
115+
116+
$this->assertSame(1, $taxonomy->queryTerms()->pluck('slug')->unique()->count());
117+
$this->assertSame(1, $taxonomy->queryTerms()->count());
118+
$this->assertSame($term->slug(), $taxonomy->queryTerms()->get()->pluck('slug')->first());
119+
}
108120
}

0 commit comments

Comments
 (0)