/** * Initialize * * @return void */ public function initialize() { if (!$this->initialized) { $this->prototype = $this->model->newFromBuilder(); } $this->initialized = true; }
public function newFromBuilder($attributes = array(), $connection = null) { if ($this->getAttribute($this->getStiClassField())) { $class = $this->getAttribute($this->getStiClassField()); $instance = new $class(); $instance->exists = true; $instance->setRawAttributes((array) $attributes, true); return $instance; } return parent::newFromBuilder($attributes, $connection); }
public function newFromBuilder($attributes = [], $connection = null) { if ($this->useSti() && $attributes->{$this->stiClassField}) { $class = $attributes->{$this->stiClassField}; $instance = new $class(); $instance->exists = true; $instance->setRawAttributes((array) $attributes, true); return $instance; } else { return parent::newFromBuilder($attributes); } }
/** * 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}; }); }
/** * Create a new model instance that is existing. * * @param array $attributes * @param string|null $connection * @return static */ public function newFromBuilder($attributes = [], $connection = null) { $model = parent::newFromBuilder($attributes, $connection); $model->fireModelEvent('reconstructed', false); /* retrieve fetch obtain reconstruct rebuild */ return $model; }
/** * Get an array with the values of a given column. * * @param string $column * @param string|null $key * @return \Illuminate\Support\Collection */ 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 = [$column => $value]; $value = $this->model->newFromBuilder($fill)->{$column}; } } return collect($results); }
/** * !! OVERRIDE ELOQUENT MODEL !! * Create a new model instance that is existing. * * @param array $attributes * @param string|null $connection * @return static */ public function newFromBuilder($attributes = [], $connection = null) { static::stiEnforceChildren(); // If there isn't a key set, just return the default if (!isset($attributes->{static::$stiKey})) { return parent::newFromBuilder($attributes, $connection); } // We create the model based on the keyed type $class = static::stiChildren()[$attributes->{static::$stiKey}]; $model = new $class(); $model->exists = true; /** The rest is copy-and-paste from eloquent */ $model->setRawAttributes((array) $attributes, true); $model->setConnection($connection ?: $this->connection); return $model; }
/** * Get the hydrated models without eager loading. * * @param array $columns * @return array|static[] */ public function getModels($columns = array('*')) { // First, we will simply get the raw results from the query builders which we // can use to populate an array with Eloquent models. We will pass columns // that should be selected as well, which are typically just everything. $results = $this->query->get($columns); $connection = $this->model->getConnectionName(); $models = array(); // Once we have the results, we can spin through them and instantiate a fresh // model instance for each records we retrieved from the database. We will // also set the proper connection name for the model after we create it. foreach ($results as $result) { $models[] = $model = $this->model->newFromBuilder($result); $model->setConnection($connection); } return $models; }
/** * {@inheritdoc} */ public function newFromBuilder($attributes = array(), $connection = null) { /** @var Node $instance */ $instance = parent::newFromBuilder($attributes, $connection); $instance->clearAction(); return $instance; }
public function newFromBuilder($attributes = array(), $connection = null) { $instance = parent::newFromBuilder($attributes); $instance->old_parent_id = $instance->parent_id; $instance->old_position = $instance->position; return $instance; }
/** * Create a new model instance that is existing. * * @param array $attributes * @return static */ public function newFromBuilder($attributes = array()) { if ($this->isRootModel() and isset($attributes->{static::$table_type_field})) { $class = $attributes->{static::$table_type_field}; $instance = $this->newInstanceOfClass($class, array(), true); $instance->setRawAttributes((array) $attributes, true); return $instance; } return parent::newFromBuilder($attributes); }