public function hasGetMutator($key) { if ($this->autoserialize_attributes) { foreach ($this->attributes_schema as $k => $value) { if ($value == 'array' && $k == $key || $value == 'object' && $k == $key) { return true; } } } return parent::hasGetMutator($key); }
/** * 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}; }); }
/** * Get an array with the values of a given column. * * @param string $column * @param string $key * @return array */ public function lists($column, $key = null) { $results = $this->query->lists($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 = array($column => $value); $value = $this->model->newFromBuilder($fill)->{$column}; } } return $results; }
/** * Retrieves a relationships nested property from a column. * * @param string $key * @param Model $model * @param mixed $value * * @return mixed */ protected function getColumnMeansProperty($key, $model, $value) { // Explode the dot notated key. $attributes = explode('.', $key); foreach ($attributes as $attribute) { // If we're at the end of the attributes array, // we'll see if the temporary object is // an instance of an Eloquent Model. if ($attribute === end($attributes)) { // If the relationship model has a get mutator // for the current attribute, we'll run it // through the mutator and pass on the // revised value. if ($model->hasGetMutator($attribute)) { $model = $model->mutateAttribute($attribute, $value); } else { // Looks like the relationship model doesn't // have a mutator for the attribute, we'll // return the models attribute. $model = $model->{$attribute}; } } else { $model = $model->{$attribute}; } } return $model; }