Illuminate\Database\Eloquent\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->toBase()->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) && !$this->model->hasCast($column) && !in_array($column, $this->model->getDates())) {
            return $results;
        }
        return $results->map(function ($value) use($column) {
            return $this->model->newFromBuilder([$column => $value])->{$column};
        });
    }

Usage Example

 public function pluck($value, $key = null)
 {
     $this->newQuery();
     $lists = $this->query->pluck($value, $key);
     if (is_array($lists)) {
         return $lists;
     }
     return $lists->all();
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::pluck