本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}