當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Builder::getModel方法代碼示例

本文整理匯總了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));
     });
 }
開發者ID:mawaha,項目名稱:tracker,代碼行數:13,代碼來源:SoftDeletingScope.php

示例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;
     });
 }
開發者ID:fparralejo,項目名稱:btrabajo,代碼行數:15,代碼來源:SoftDeletingScope.php

示例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;
     });
 }
開發者ID:alsvader,項目名稱:sacd,代碼行數:14,代碼來源:SoftDeletingScope.php

示例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;
 }
開發者ID:naturalweb,項目名稱:nwlaravel,代碼行數:83,代碼來源:InputCriteria.php


注:本文中的Builder::getModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。