/** * 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->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}; }); }
/** * Cast the changes collection to the appropiate type. * * @param Collection $changes * @param Model $adjustment * @return mixed */ protected function castChanges(Collection $changes, Model $adjustment) { $cast = $adjustment->hasCast(config('adjuster.changes_column')); switch ($cast) { case 'collection': return $changes; case 'array': case 'json': return $changes->toArray(); default: return $changes->toJson(); } }