本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::first方法的具体用法?PHP Builder::first怎么用?PHP Builder::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::first方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByCredentials
/**
* @inheritdoc
*/
public function getByCredentials(array $credentials)
{
foreach ($credentials as $key => $value) {
if (strpos($key, 'password') === false) {
$this->queryBuilder->where($key, $value);
}
}
return $this->queryBuilder->first();
}
示例2: first
/**
* @param array $columns
*
* @return \Illuminate\Database\Eloquent\Model|null|static
*/
public function first($columns = array('*'))
{
if (count($this->query->orders) == 0) {
$this->orderBy(static::COLUMN_MODEL_ID);
}
return parent::first($columns);
}
示例3: first
/**
* Get the first specified model record from the database
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function first()
{
$this->newQuery()->eagerLoad()->setClauses();
$model = $this->query->first();
$this->unsetClauses();
return $model;
}
示例4: first
/**
* Return the first element
*
* @return Collection
*/
public function first()
{
// Save the results from the builder
$result = $this->builder->first();
// Reset the builder, just in case we are going to use this repository more then once
$this->newBuilder();
return $result;
}
示例5: getEntity
/**
* @return mixed|null
*/
public function getEntity()
{
/** @var DoplioDbTable|null $result */
$result = $this->specificationQuery->first();
if (!$result) {
return null;
}
return $this->mapper->fromDbTableRow($result);
}
示例6: update
/**
* @param $id
* @param $data
* @param bool $orFail
* @return mixed
*
* updates an existing record
*/
public function update($id, $data, $orFail = false)
{
if ($id instanceof Model) {
$this->model = $id;
} else {
$this->model = new $this->modelClass();
$table = $this->model->getTable();
$this->model = $this->model->newQuery();
$this->model->where($table . '.' . $this->identifier, '=', $id);
$this->model = $orFail ? $this->model->firstOrFail() : $this->model->first();
if (!$this->model) {
return false;
}
}
if (!is_array($data)) {
$data = $this->extractData($data);
}
$this->model->fill($data);
foreach ($this->updateDefaults() as $key => $value) {
$this->model->{$key} = $value;
}
$this->model->save();
return $this->model;
}
示例7: first
/**
* Execute the query and get the first result.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|static|null
* @static
*/
public static function first($columns = array())
{
return \Illuminate\Database\Eloquent\Builder::first($columns);
}
示例8: first
/**
* Return the first entry.
*
* @param array $columns
* @return EloquentModel|EntryInterface
*/
public function first(array $columns = ['*'])
{
return (new Decorator())->decorate($this->query->first($columns));
}
示例9: first
/**
* @param Builder $builder
* @return Model
*/
protected function first(Builder $builder)
{
return $builder->first();
}
示例10: executeQuery
/**
* Query execution function called by getters.
* All repository getters should call this for integrated caching at the repository level.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $columns The columns to retrieve
* @param bool $first Limit to one result or not
* @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|null
*/
protected function executeQuery($query, $first)
{
$tag = $this->cacheTag ?: $this->untagged;
$builder = $query->getQuery();
$key = $this->getQueryKey($builder, $first);
if ($first) {
return Cache::tags(['repositories', $tag])->remember($key, $this->cacheDuration, function () use($query) {
return $query->first();
});
} else {
return Cache::tags(['repositories', $tag])->remember($key, $this->cacheDuration, function () use($query) {
return $query->get();
});
}
}
示例11: first
/**
* @param array $columns
* @return Model|Collection
*/
public function first($columns = ['*'])
{
/** @var Model $result */
$model = parent::first($columns);
return $model ?: $this->model->newInstance([]);
}