Skip to content

Commit 0f8abc9

Browse files
committed
fix column() & pluck() methods
1 parent f4038d0 commit 0f8abc9

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/QueryBuilder.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,25 @@ public function count($table, string $field = '')
212212
}
213213

214214
/**
215-
* @param int|string $column
215+
* @param string $column
216216
* @return $this|string|array
217217
*/
218-
public function column($column = 0)
218+
public function column(string $column = 'id')
219219
{
220-
if (is_integer($column) or is_string($column)) {
220+
if (!is_string($column)) {
221221
$this->setError('Incorrect type of $column in ' . __METHOD__);
222222
return $this;
223223
}
224224

225-
$this->query('', [], $column, self::FETCH_COLUMN);
226-
return $this->result;
225+
if (empty($column)) {
226+
$this->setError('Empty $column in ' . __METHOD__);
227+
return $this;
228+
}
229+
230+
$this->query();
231+
return array_column($this->result, $column);
232+
//$this->query('', [], $column, self::FETCH_COLUMN);
233+
//return $this->result;
227234
}
228235

229236
/**
@@ -236,17 +243,22 @@ public function exists(): bool
236243
}
237244

238245
/**
239-
* @param string|int $key
240-
* @param string|int $column
246+
* @param string $key
247+
* @param string $column
241248
* @return array|QueryBuilder
242249
*/
243-
public function pluck($key = 0, $column = 1): array
250+
public function pluck(string $key = 'id', string $column = '')
244251
{
245-
if ((is_integer($key) or is_integer($column)) or (is_string($key) or is_string($column))) {
252+
if (!(is_string($key) and is_string($column))) {
246253
$this->setError('Incorrect type of $key or $column in ' . __METHOD__);
247254
return $this;
248255
}
249256

257+
if (empty($column)) {
258+
$this->setError('Empty $column in ' . __METHOD__);
259+
return $this;
260+
}
261+
250262
$this->query();
251263
return array_column($this->result, $column, $key);
252264
}

0 commit comments

Comments
 (0)