Skip to content

Commit

Permalink
[10.x] Added missing expression support for pluck (laravel#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
2 people authored and chu121su12 committed Feb 20, 2023
1 parent b47e58b commit cd71831
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 @@ -2935,7 +2935,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 @@ -2981,9 +2981,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 cd71831

Please sign in to comment.