本文整理汇总了PHP中Builder::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::getModel方法的具体用法?PHP Builder::getModel怎么用?PHP Builder::getModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder::getModel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRestore
/**
* Add the restore extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
protected function addRestore(Builder $builder)
{
$builder->macro('restore', function (Builder $builder) {
$builder->withTrashed();
return $builder->update(array($builder->getModel()->getDeletedAtColumn() => null));
});
}
示例2: addOnlyTrashed
/**
* Add the only-trashed extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
protected function addOnlyTrashed(Builder $builder)
{
$builder->macro('onlyTrashed', function (Builder $builder) {
$model = $builder->getModel();
$this->remove($builder, $model);
$builder->getQuery()->whereNotNull($model->getQualifiedDeletedAtColumn());
return $builder;
});
}
示例3: addOnlyTrashed
/**
* Add the only-trashed extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
protected function addOnlyTrashed(Builder $builder)
{
$builder->macro('onlyTrashed', function (Builder $builder) {
$model = $builder->getModel();
$builder->withoutGlobalScope($this)->whereNotNull($model->getQualifiedDeletedAtColumn());
return $builder;
});
}
示例4: apply
/**
* Apply criteria in query
*
* @param Builder $query
*
* @return mixed
*/
public function apply($query, RepositoryInterface $repository = null)
{
if ($repository) {
$this->searchables = array_merge($this->searchables, $repository->getFieldsSearchable());
}
if ($nameSearchable = config('repository.criteria.params.search')) {
$this->setNameSearchable($nameSearchable);
}
if ($orderBy = config('repository.criteria.params.orderBy')) {
$this->setFieldOrderBy($orderBy);
}
if ($sortedBy = config('repository.criteria.params.sortedBy')) {
$this->setFieldSortedBy($sortedBy);
}
$model = $query;
if ($query instanceof EloquentBuilder) {
$model = $query->getModel();
}
if ($model instanceof Model) {
$this->dates = $model->getDates();
$this->table = $model->getTable() . '.';
}
if ($model instanceof AbstractEntity) {
$this->addColumns($model->columns());
}
foreach ($this->input as $key => $value) {
// Parameter Grouping
if ($value instanceof \Closure) {
$query = $query->where($value);
continue;
}
// Scope
$methodScope = 'scope' . studly_case($key);
if (is_object($model) && method_exists($model, $methodScope)) {
$methodName = camel_case($key);
$query = $query->{$methodName}($value);
continue;
}
// Where Search
if ($key === $this->nameSearchable) {
$query = $this->whereSearch($query, $value);
continue;
}
if (is_int($key)) {
// Using A Raw Expression
if ($value instanceof QueryExpression) {
$query = $query->whereRaw($value);
}
/**
* Using String Format
* eg: {field},{operator},{value}
*/
if (is_string($value) && preg_match('/^([a-zA-Z0-9_]+),(.+),(.+)$/', $value, $matches)) {
if (count($matches) == 4) {
$value = array_splice($matches, 1, 3);
}
}
/**
* Using Array com Operator
* eg: ex: ('field', '=', 'value') or ('field', 'value')
*/
if (is_array($value) && count($value)) {
$value = array_pad($value, 3, null);
list($field, $operator, $valor) = array_splice($value, 0, 3);
$query = $this->whereCriteria($query, $field, $operator, $valor);
}
continue;
}
$query = $this->whereCriteria($query, $key, '=', $value);
}
// Order By
if ($this->orderBy && in_array($this->orderBy, $this->columns)) {
$query = $query->orderBy($this->orderBy, $this->sortedBy);
}
return $query;
}