newFromBuilder() public method

Create a new model instance that is existing.
public newFromBuilder ( array $attributes = [], string | null $connection = null ) : static
$attributes array
$connection string | null
return static
Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
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->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};
     });
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * 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;
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function newFromBuilder($attributes = array(), $connection = null)
 {
     /** @var Node $instance */
     $instance = parent::newFromBuilder($attributes, $connection);
     $instance->clearAction();
     return $instance;
 }
Exemplo n.º 10
0
 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);
 }