Illuminate\Database\Query\Builder::pluck PHP Method

pluck() public method

Get an array with the values of a given column.
public pluck ( string $column, string | null $key = null ) : Collection
$column string
$key string | null
return Illuminate\Support\Collection
    public function pluck($column, $key = null)
    {
        $results = $this->get(is_null($key) ? [$column] : [$column, $key]);
        // If the columns are qualified with a table or have an alias, we cannot use
        // those directly in the "pluck" operations since the results from the DB
        // are only keyed by the column itself. We'll strip the table out here.
        return $results->pluck($this->stripTableForPluck($column), $this->stripTableForPluck($key));
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string|null  $key
  * @return \Illuminate\Support\Collection
  */
 public function pluck($column, $key = null)
 {
     $results = $this->query->pluck($column, $key);
     // If the model has a mutator for the requested column, we will spin through
     // the results and mutate the values so that the mutated version of these
     // columns are returned as you would expect from these Eloquent models.
     if ($this->model->hasGetMutator($column)) {
         foreach ($results as $key => &$value) {
             $fill = [$column => $value];
             $value = $this->model->newFromBuilder($fill)->{$column};
         }
     }
     return collect($results);
 }
All Usage Examples Of Illuminate\Database\Query\Builder::pluck