本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::newFromBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::newFromBuilder方法的具体用法?PHP Model::newFromBuilder怎么用?PHP Model::newFromBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::newFromBuilder方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Initialize
*
* @return void
*/
public function initialize()
{
if (!$this->initialized) {
$this->prototype = $this->model->newFromBuilder();
}
$this->initialized = true;
}
示例2: newFromBuilder
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);
}
示例3: newFromBuilder
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);
}
}
示例4: pluck
/**
* 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};
});
}
示例5: newFromBuilder
/**
* 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;
}
示例6: lists
/**
* 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);
}
示例7: newFromBuilder
/**
* !! 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;
}
示例8: getModels
/**
* 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;
}
示例9: newFromBuilder
/**
* {@inheritdoc}
*/
public function newFromBuilder($attributes = array(), $connection = null)
{
/** @var Node $instance */
$instance = parent::newFromBuilder($attributes, $connection);
$instance->clearAction();
return $instance;
}
示例10: newFromBuilder
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;
}
示例11: newFromBuilder
/**
* 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);
}