Skip to content

Commit 1223326

Browse files
committed
Support pluck() on eloquent query builder
1 parent dac04b9 commit 1223326

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Query/EloquentQueryBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ public function get($columns = ['*'])
7777
return $items;
7878
}
7979

80+
public function pluck($column, $key = null)
81+
{
82+
$items = $this->get();
83+
84+
if (! $key) {
85+
return $items->map(fn($item) => $item->{$column})->values();
86+
}
87+
88+
return $items->mapWithKeys(fn($item) => [$item->{$key} => $item->{$column}]);
89+
}
90+
8091
public function first()
8192
{
8293
return $this->get()->first();

0 commit comments

Comments
 (0)