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


PHP Model::where方法代码示例

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


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

示例1: getAds

 public function getAds()
 {
     $query = $this->model->where('active', 1)->whereHas('photos', function ($q) {
         $q->latest()->take(1);
     })->take(2)->get();
     return $query;
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:7,代码来源:AdRepository.php

示例2: get

 /**
  * Get an Item from storage with optional relations
  *
  * @param $id
  * @param array $with
  * @return Item
  */
 public function get($id, $with = [])
 {
     if (count($with)) {
         return $this->model->where('id', '=', $id)->with($with)->first();
     }
     return $this->model->find($id);
 }
开发者ID:brycenrogers,项目名称:linken,代码行数:14,代码来源:BaseRepository.php

示例3: findBy

 /**
  * @param string $name
  * @param mixed $value
  * @return null|object
  */
 public function findBy($name, $value)
 {
     $model = $this->model->where($name, strtolower($value));
     if ($model) {
         return $this->convertFormat($model->first());
     }
     return null;
 }
开发者ID:lyovkin,项目名称:v2board,代码行数:13,代码来源:AbstractRepository.php

示例4: where

 /**
  * Return all object within the where conditions
  * Best Usage with compact('value1', 'value2')
  *
  * @param $args
  * @return Collection|mixed
  */
 public function where($args)
 {
     /**
      * Remove if value is set to all so everything would be selected
      */
     $args = collect($args)->filter(function ($value) {
         return $value != 'all' ?: false;
     });
     return $this->model->where($args->toArray())->get();
 }
开发者ID:SkysoulDesign,项目名称:TempArk,代码行数:17,代码来源:Repository.php

示例5: search

 /**
  * @param array $searchParams
  * @param int $limit
  * @param int $offset
  * @return mixed
  */
 public function search($searchParams, $limit = 0, $offset = 0)
 {
     $query = $this->model->where('id', '!=', 0);
     foreach ($searchParams as $field => $value) {
         $query->where($field, '=', $value);
     }
     if ($limit > 0) {
         $query->take($limit)->skip($offset);
     }
     $results = $query->get();
     return $this->getCollection($results);
 }
开发者ID:alistairshaw,项目名称:ambitiousmail-relay,代码行数:18,代码来源:AbstractEloquentRepository.php

示例6: apply

 public function apply(Model $model, RepositoryContract $repository)
 {
     $fields = $this->fields;
     $query = $this->query;
     if (!$fields) {
         $fields = $model->getFillable();
     }
     switch ($this->type) {
         case self::$ST_USE_AT_BEGIN:
             $query = '%' . $this->query;
             break;
         case self::$ST_USE_AT_END:
             $query = $this->query . '%';
             break;
         case self::$ST_USE_AT_BOTH:
             $query = '%' . $this->query . '%';
             break;
     }
     $query = $model->where(function ($q) use($fields, $query) {
         foreach ($fields as $i => $field) {
             if ($i == 0) {
                 $q->where($field, 'like', $query);
             }
             $q->orWhere($field, 'like', $query);
         }
     });
     return $query;
 }
开发者ID:nch7,项目名称:RepositoriesPattern,代码行数:28,代码来源:FindUsingLikeCriteria.php

示例7: 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;
 }
开发者ID:prjkt,项目名称:repofuck,代码行数:38,代码来源:Repofuck.php

示例8: retrieve_range_id

 public static function retrieve_range_id($book, $chapter, $range)
 {
     $closingVerse;
     $verse = parent::where('Book', '=', $book)->where('Chapter', '=', $chapter)->where('Verse', '<=', $range)->orderBy('id', 'desc')->first();
     $return = array('id' => $verse->id, 'chapter' => $verse->Chapter, 'verse' => $verse->Verse);
     return $return;
 }
开发者ID:sjones6,项目名称:auto-linker,代码行数:7,代码来源:Verse.php

示例9: scanTable

 /**
  * Export a column from a table.
  *
  * @param resource $fp
  * @param Model    $entity
  * @param string   $key_column
  * @param string   $data_column
  * @param string   $comment
  */
 private function scanTable($fp, Model $entity, $key_column, $data_column, $comment)
 {
     $table = $entity->getTable();
     $this->info($table . '...');
     foreach ($entity->where($data_column, '<>', '')->get() as $item) {
         fprintf($fp, self::PO_FORMAT, 'DATABASE: ' . $key_column . '="' . $item->getAttribute($key_column) . '"', $comment, $item->getAttribute($data_column));
     }
 }
开发者ID:fisharebest,项目名称:webtrees-core,代码行数:17,代码来源:DumpPotCommand.php

示例10: whereEndsWith

 /**
  * 当前属性以特定字符串结尾
  * @param $attribute
  * @param string|null $value
  * @return static
  */
 public function whereEndsWith($attribute, string $value)
 {
     if (is_empty_string($value)) {
         return $this;
     }
     $this->original->where($attribute, 'like', '%' . trim($value, '%'));
     return $this;
 }
开发者ID:wutongwan,项目名称:laravel-lego,代码行数:14,代码来源:EloquentTable.php

示例11: findByIdOrAlias

 /**
  * Find by id or alias
  *
  * @param  string $idOrAlias
  * @return Category
  */
 public static function findByIdOrAlias($idOrAlias)
 {
     $category = parent::find($idOrAlias);
     if ($category) {
         return $category;
     }
     return parent::where('alias', $idOrAlias)->first();
 }
开发者ID:toancong,项目名称:laravel-articles,代码行数:14,代码来源:Category.php

示例12: findAllByFieldPaginated

 public function findAllByFieldPaginated($field, $value = null, $operator = '=', $perPage = null, $orderBy = null, $with = null, $columns = array('*'))
 {
     $query = $this->model->where($field, $operator, $value);
     $query = $this->applyAllClauses($query, $orderBy, $with);
     $models = $query->paginate($this->perPage($perPage), $columns);
     $this->resetModel();
     return $this->parseResult($models);
 }
开发者ID:mayconbordin,项目名称:reloquent,代码行数:8,代码来源:BaseRepository.php

示例13: where

 /**
  * @param array  $where
  * @param string $boolean
  * @return $this
  */
 public function where(array $where, $boolean = 'and')
 {
     foreach ($where as $k => $v) {
         list($field, $condition, $value) = is_array($v) ? $v : [$k, '=', $v];
         $this->model = $this->model->where($field, $condition, $value, $boolean);
     }
     return $this;
 }
开发者ID:guilhermegonzaga,项目名称:repository,代码行数:13,代码来源:Repository.php

示例14: findAllBy

 /**
  * @param $field
  * @param $value
  * @return mixed
  */
 public function findAllBy($field, $value, array $with = array())
 {
     $this->addWithCriteria($with);
     $this->applyCriteria();
     $result = $this->model->where($field, '=', $value)->get();
     $this->refresh();
     return $result;
 }
开发者ID:ablunier,项目名称:laravel-database,代码行数:13,代码来源:Repository.php

示例15: createOrFail

 /**
  * @param array $input
  * @param array $criteria
  * @return static|bool
  */
 public function createOrFail($input, $criteria)
 {
     $object = $this->model->where($criteria)->get();
     if ($object->isEmpty()) {
         return $this->create($input);
     } else {
         return null;
     }
 }
开发者ID:khuesmann,项目名称:artisan-create,代码行数:14,代码来源:AbstractEloquentRepository.php


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