本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getModel方法的具体用法?PHP Model::getModel怎么用?PHP Model::getModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::getModel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* @param Model|Builder $model
* @return Model
*/
public function search($model)
{
if ($model instanceof SearchableModel) {
$this->fieldConfig = $model->searchableFields();
$this->primaryTable = $model->getTable();
}
if ($model instanceof Relation) {
$this->primaryTable = $model->getModel()->getTable();
$this->fieldConfig = $model->getModel()->searchableFields();
$this->apply($model->getQuery());
return $model;
}
return $this->apply($model);
}
示例2: generateFromRelations
public function generateFromRelations()
{
$this->parent = $this->query->getModel();
foreach (explode('.', $this->relations) as $index => $relation) {
$this->index = $index;
$this->relation = call_user_func(array($this->parent, $relation));
$this->related = $this->relation->getRelated();
if ($this->nested) {
if (!array_key_exists($this->index, $this->ons)) {
$this->ons[$this->index] = [];
}
if (!array_key_exists($this->index, $this->conditions)) {
$this->conditions[$this->index] = [];
}
}
if ($this->relation instanceof BelongsTo) {
$this->generateJoinFromBelongsTo($this->relation);
} elseif ($this->relation instanceof BelongsToMany) {
$this->generateJoinFromBelongsToMany($this->relation);
} elseif ($this->relation instanceof HasOneOrMany) {
$this->generateJoinFromHasOneOrMany($this->relation);
}
$this->parent = $this->relation->getRelated();
}
if ($this->addNullCondition) {
if ($this->relation instanceof BelongsTo) {
$this->generateNullConditionFromBelongsTo($this->relation);
} elseif ($this->relation instanceof BelongsToMany) {
$this->generateNullConditionFromBelongsToMany();
} elseif ($this->relation instanceof HasOneOrMany) {
$this->generateNullConditionFromHasOneOrMany($this->relation);
}
}
}
示例3: where
/**
* Sets the where clause to the current entity.
*
* @param array|Closure $query
* @param bool $append
* @return self
*/
public function where($query, $append = false)
{
$entity = $this->entity;
switch ($query) {
case $query instanceof Closure:
// Overwrite: Strip down the Builder to a Model when
// the current entity has a where clause and $append is false
if (!$append && $entity instanceof Builder) {
$entity = $this->entity->getModel();
}
// Supplied callback return to be attached
try {
$entity = call_user_func($query, $entity);
if (!$entity instanceof Builder) {
throw new InvalidCallbackReturn();
}
} catch (InvalidCallbackReturn $e) {
//Retain the current entity as it was before this method's call.
$entity = $this->entity;
}
// Assign the entity with the newly attached where clause
$this->entity = $entity;
break;
case is_array($query):
foreach ($query as $clause) {
$this->entity->where($clause);
}
break;
}
return $this;
}
示例4: refresh
/**
*
*/
protected function refresh()
{
if (!$this->model instanceof EloquentModel) {
$this->model = $this->model->getModel();
}
$this->model = $this->model->newInstance();
$this->criteria = new Collection();
}
示例5: getFillable
/**
* Get the fillable attributes for the model.
*
* @return array
*/
protected function getFillable()
{
return $this->model instanceof Builder ? $this->model->getModel()->getFillable() : $this->model->getFillable();
}
示例6: scopeWhereInSubQuery
/**
* @param EloquentBuilder|QueryBuilder|Model $query
* @param string $column
* @param EloquentBuilder|QueryBuilder|Model $subQuery
* @param string $subQueryColumn
*
* @return QueryBuilder
*/
public function scopeWhereInSubQuery($query, $column, $subQuery, $subQueryColumn)
{
if (!Str::contains($column, '.')) {
/** @var Model|BetterEloquentTrait $model */
$model = $query->getModel();
$column = $model->getField($column);
}
$subQuery = $subQuery->toSubQuery($subQueryColumn, true);
return $query->whereIn($column, $subQuery);
}