当前位置: 首页>>代码示例>>PHP>>正文


PHP Builder::orWhere方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::orWhere方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::orWhere方法的具体用法?PHP Builder::orWhere怎么用?PHP Builder::orWhere使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Builder的用法示例。


在下文中一共展示了Builder::orWhere方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: applyFilters

 private function applyFilters(Builder $query, $expression, $value, $multiple = false)
 {
     $equalsFilter = false;
     $field = null;
     $filter = explode(":", $expression);
     // filter[field:filter]=value
     if (count($filter) == 2) {
         $field = $filter[0];
         $filter = $filter[1];
     } else {
         $equalsFilter = true;
         $field = $expression;
     }
     // filter[field]=value
     if ($equalsFilter) {
         $multiple ? $query->orWhere($field, '=', $value) : $query->where($field, '=', $value);
     }
     // filter[field:between]=A,B
     if ($this->isBetweenFilter($filter)) {
         $betweenValues = $this->getBetweenValues($value);
         if (count($betweenValues) != 2) {
             throw new BadRequestHttpException("Please specify two numbers to filter between");
         }
         $multiple ? $query->orWhereBetween($field, $betweenValues) : $query->whereBetween($field, $betweenValues);
     }
     // filter[field:[after, before, greater_than, less_than]]=value
     if ($this->isComparisonFilter($filter)) {
         if ($this->isDateFilter($field)) {
             $value = Carbon::createFromTimestamp($value);
         }
         $comparisonFilter = $this->getComparisonFilter($filter);
         $multiple ? $query->orWhere($field, $comparisonFilter, $value) : $query->where($field, $comparisonFilter, $value);
     }
     // filter[field:[contains, ends_with, starts_with]]=value
     if ($this->isWildcardFilter($filter)) {
         $value = $this->getLikeWildcard($filter, $value);
         $multiple ? $query->orWere($field, 'like', $value) : $query->where($field, 'like', $value);
     }
     // filter[field:trashed]=true
     if ($this->isTrashedFilter($field)) {
         $query->onlyTrashed();
     }
 }
开发者ID:hrobinson,项目名称:laravel-core,代码行数:43,代码来源:FilterableRepository.php

示例2: transferLocalImages

 /**
  * Transfer local images to cloud storage.
  */
 public function transferLocalImages()
 {
     $this->imageResource->orWhere(function (Builder $query) {
         $query->where('filename', '!=', '');
         $query->whereNotNull('filename');
     })->get()->each(function (Image $image) {
         $this->dispatcher->fire(new NewImageEvent($image));
     });
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:12,代码来源:ImageRepository.php

示例3: virtualFulltextSearchColumns

 /**
  * Search columns like fulltext do
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param string $word
  * @param array $fields
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public static function virtualFulltextSearchColumns(Builder $query, $word, $fields)
 {
     if (isset($word) && strlen($word) > 0) {
         $first = TRUE;
         foreach ($fields as $fieldName => $fieldAttributes) {
             /**
              * Empty attributes
              */
             if (is_numeric($fieldName) == TRUE) {
                 $fieldName = $fieldAttributes;
                 $fieldAttributes = ['operator' => '=', 'prefix' => '', 'sufix' => ''];
             }
             if (isset($fieldAttributes['operator']) == FALSE) {
                 $fieldAttributes['operator'] = '=';
             }
             if (isset($fieldAttributes['prefix']) == FALSE) {
                 $fieldAttributes['prefix'] = '';
             }
             if (isset($fieldAttributes['sufix']) == FALSE) {
                 $fieldAttributes['sufix'] = '';
             }
             /**
              * Query builder
              */
             if ($first == TRUE) {
                 $query->where($fieldName, $fieldAttributes['operator'], $fieldAttributes['prefix'] . $word . $fieldAttributes['sufix']);
                 $first = FALSE;
             } else {
                 $query->orWhere($fieldName, $fieldAttributes['operator'], $fieldAttributes['prefix'] . $word . $fieldAttributes['sufix']);
             }
         }
     }
     return $query;
 }
开发者ID:jdrda,项目名称:olapus,代码行数:42,代码来源:Helpers.php

示例4: handle

 /**
  * Handle the filter.
  *
  * @param Builder               $query
  * @param SearchFilterInterface $filter
  */
 public function handle(Builder $query, TableBuilder $builder, SearchFilterInterface $filter)
 {
     $stream = $filter->getStream();
     $model = $builder->getTableModel();
     /**
      * If the model is translatable then
      * join it's translations so they
      * are filterable too.
      *
      * @var EloquentQueryBuilder $query
      */
     if ($model->getTranslationModelName() && !$query->hasJoin($model->getTranslationTableName())) {
         $query->leftJoin($model->getTranslationTableName(), $model->getTableName() . '.id', '=', $model->getTranslationTableName() . '.' . $model->getRelationKey());
     }
     $query->where(function (Builder $query) use($filter, $stream) {
         foreach ($filter->getColumns() as $column) {
             $query->orWhere($column, 'LIKE', "%{$filter->getValue()}%");
         }
         foreach ($filter->getFields() as $field) {
             $filter->setField($field);
             $fieldType = $stream->getFieldType($field);
             $fieldTypeQuery = $fieldType->getQuery();
             $fieldTypeQuery->setConstraint('or');
             $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder'));
         }
     });
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:33,代码来源:SearchFilterQuery.php

示例5: searchFor

 /**
  * @param       $value
  * @param array $in
  * @return Model
  */
 public function searchFor($value, array $in)
 {
     foreach ($in as $key) {
         $this->model = $this->model->orWhere($key, $value);
     }
     return $this->model->firstOrFail();
 }
开发者ID:crip-laravel,项目名称:core,代码行数:12,代码来源:Repository.php

示例6: notifyLast

 private function notifyLast(Builder $query, $type)
 {
     $current = $this->ticket->events->first()->id;
     foreach ($this->ticket->actions as $action) {
         if ($action->id == $current) {
             break;
         }
         $last = $action;
     }
     return $query->orWhere('id', $last->user_id);
 }
开发者ID:hughfletcher,项目名称:nuticket,代码行数:11,代码来源:WhereNotify.php

示例7: search

 /**
  * @param $search
  * @param $columns
  * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query
  * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
  */
 protected function search($search, $columns, $query)
 {
     if ($search) {
         $query->where(function ($query) use($search, $columns) {
             foreach ($columns as $column) {
                 $query->orWhere($column, 'LIKE', "%{$search}%");
             }
         });
     }
     return $query;
 }
开发者ID:snowfire,项目名称:sprinkles,代码行数:17,代码来源:Repository.php

示例8: scopeWithTranslation

 /**
  * This scope eager loads the translations for the default and the fallback locale only.
  * We can use this as a shortcut to improve performance in our application.
  *
  * @param Builder $query
  */
 public function scopeWithTranslation(Builder $query)
 {
     $query->with(['translations' => function ($query) {
         $query->where(function ($query) {
             $query->where($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->locale());
             if ($this->useFallback()) {
                 return $query->orWhere($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->getFallbackLocale($this->locale()))->orWhere($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->getFallbackLocale());
             }
         });
     }]);
 }
开发者ID:kitbs,项目名称:vinfo,代码行数:17,代码来源:TranslatableSortable.php

示例9: applyQuery

 /**
  * Aplicar estrutura de busca em uma BuilderQuery.
  *
  * @param Builder $query
  * @param array $groups
  */
 public function applyQuery(Builder $query, array $groups)
 {
     $query->where(function ($query) use($groups) {
         foreach ($groups as $items) {
             $query->orWhere(function ($query) use($items) {
                 foreach ($items as $item) {
                     $query->where($item->field, $item->op, $item->value, $item->link);
                 }
             });
         }
     });
 }
开发者ID:bugotech,项目名称:database,代码行数:18,代码来源:SearchModel.php

示例10: scopeSearch

 /**
  * @param \Illuminate\Database\Eloquent\Builder|static $query
  * @param string $keyword
  * @param boolean $matchAllFields
  */
 public static function scopeSearch($query, $keyword, $matchAllFields = false)
 {
     return static::where(function ($query) use($keyword, $matchAllFields) {
         foreach (static::getSearchFields() as $field) {
             if ($matchAllFields) {
                 $query->where($field, 'LIKE', "%{$keyword}%");
             } else {
                 $query->orWhere($field, 'LIKE', "%{$keyword}%");
             }
         }
     });
 }
开发者ID:eezhal92,项目名称:plw-webdev,代码行数:17,代码来源:SearchTrait.php

示例11: filter

 private function filter(\Illuminate\Database\Eloquent\Builder $_db)
 {
     $_db->take($this->limit);
     if (Request::get('offset')) {
         $_db->skip(Request::get('offset'));
     }
     if (Request::get('q')) {
         $_db->where('name', 'like', Request::get('q') . '%');
         $_db->orWhere('lastname', 'like', Request::get('q') . '%');
     }
     return $_db;
 }
开发者ID:PingadoWeb,项目名称:deliveryApi,代码行数:12,代码来源:UsersRepository.php

示例12: scopeForModel

 /**
  * Constrain a query to an ability for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function scopeForModel($query, Model $model)
 {
     $query->where(function ($query) use($model) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model) {
             $query->whereNull('entity_id');
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
开发者ID:Gummibeer,项目名称:bouncer,代码行数:19,代码来源:Ability.php

示例13: search

 /**
  * Apply a list of filters to an SQL query
  *
  * @param Builder $query  The query to apply the search to.
  * @param array   $fields The fields and terms to apply to the query.
  *
  * @return self
  */
 public static function search(Builder $query, array $fields = [])
 {
     array_walk($fields, function ($values, $field) use($query) {
         $query->where($field, 'LIKE', array_shift($values));
         if (count($values) === 0) {
             return $query;
         }
         $query->where(function ($query) use($field, $values) {
             array_walk($values, function ($value) use($field, $query) {
                 $query->orWhere($field, 'LIKE', $value);
             });
         });
     });
     return $query;
 }
开发者ID:lovett,项目名称:toils,代码行数:23,代码来源:Search.php

示例14: buildScopreInPeriode

 /**
  * Filter query result for a given period
  * @param  EloquentBuilder $query  Query
  * @param  \Carboǹ\Carbon|null $after Start of the period
  * @param  \Carboǹ\Carbon|null $before End of the period
  * @return \Illuminate\Database\Eloquent\Builder Query
  */
 private function buildScopreInPeriode(EloquentBuilder $query, $after, $before)
 {
     return $query->where(function (EloquentBuilder $query) use($after, $before) {
         if ($after instanceof Carbon) {
             $query->where('date', '>=', $after);
         }
         if ($before instanceof Carbon) {
             $query->where(function (EloquentBuilder $query) use($after, $before) {
                 $query->where('date', '<=', $before);
                 if ($after instanceof Carbon === false) {
                     $query->orWhere('date', null);
                 }
             });
         }
     });
 }
开发者ID:simondubois,项目名称:budget,代码行数:23,代码来源:Operation.php

示例15: relatedEventsOutcome

 /**
  * @param EloquentBuilder $query
  */
 private function relatedEventsOutcome(EloquentBuilder $query)
 {
     $query->orWhere(function (EloquentBuilder $query) {
         $query->where('entity_type', 'App\\Outcome')->whereIn('entity_id', function (QueryBuilder $query) {
             $query->select('id')->from('outcomes')->whereIn('envelope_id', function (QueryBuilder $query) {
                 $query->select('id')->from('envelopes')->where('account_id', $this->id);
             });
         });
     });
 }
开发者ID:simondubois,项目名称:budget,代码行数:13,代码来源:AccountRelatedEvents.php


注:本文中的Illuminate\Database\Eloquent\Builder::orWhere方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。