Skip to content

Commit

Permalink
[10.x] Added missing expression support for pluck (#46146)
Browse files Browse the repository at this point in the history
* [10.x] Added missing expression support for pluck

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
ahmett and taylorotwell authored Feb 16, 2023
1 parent ae1c492 commit d973251
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,7 @@ protected function enforceOrderBy()
/**
* Get a collection instance containing the values of a given column.
*
* @param string $column
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
* @param string|null $key
* @return \Illuminate\Support\Collection
*/
Expand Down Expand Up @@ -2963,9 +2963,13 @@ protected function stripTableForPluck($column)
return $column;
}

$separator = str_contains(strtolower($column), ' as ') ? ' as ' : '\.';
$columnString = $column instanceof ExpressionContract
? $this->grammar->getValue($column)
: $column;

$separator = str_contains(strtolower($columnString), ' as ') ? ' as ' : '\.';

return last(preg_split('~'.$separator.'~i', $column));
return last(preg_split('~'.$separator.'~i', $columnString));
}

/**
Expand Down

0 comments on commit d973251

Please sign in to comment.