本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::firstOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::firstOrFail方法的具体用法?PHP Builder::firstOrFail怎么用?PHP Builder::firstOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::firstOrFail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: first
/**
* Get the first specified model record from the database
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function first()
{
$this->newQuery()->eagerLoad()->setClauses()->setScopes();
$model = $this->query->firstOrFail();
$this->unsetClauses();
return $model;
}
示例2: 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();
}
示例3: 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;
}
示例4: firstOrFail
/**
* Execute the query and get the first result or throw an exception.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|static
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
* @static
*/
public static function firstOrFail($columns = array())
{
return \Illuminate\Database\Eloquent\Builder::firstOrFail($columns);
}
示例5: first
/**
* @param array $columns
* @return mixed
*/
public function first()
{
$this->applyCriteria();
return $this->execute($this->model->firstOrFail());
}