本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::findOrFail方法的具体用法?PHP Builder::findOrFail怎么用?PHP Builder::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::findOrFail方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findOrFail
/**
* Find a model by its primary key or throw an exception.
*
* @param mixed $id
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function findOrFail($id, $columns = ['*'])
{
// Try-catch block to have the exception thrown from the repository instead of the model.
try {
$results = $this->model->findOrFail($id, $columns);
$this->reset();
if ($results = $this->hookFindOrFail($results)) {
return $results;
}
} catch (ModelNotFoundException $e) {
}
throw (new ModelNotFoundException())->setModel(static::$modelClass);
}
示例2: putCategoryParent
/**
* @param int $id
* @param Request $request
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*
* @return \Illuminate\Http\RedirectResponse
*/
public function putCategoryParent(int $id, Request $request)
{
/** @var Category $category */
$category = $this->category->findOrFail($id);
if ((int) $request->get('parent-id') === -1) {
$category->makeRoot();
$this->webUi->successMessage("Made `{$category->name}` a root-level category.");
return $this->webUi->redirect('categories.index');
}
/** @var Category $parent */
$parent = $this->category->findOrFail($request->get('parent-id'));
$category->makeChildOf($parent);
$this->webUi->successMessage("Made `{$category->name}` a child of `{$parent->name}`.");
return $this->webUi->redirect('categories.index');
}
示例3: findOrFail
/**
* Find a model by its primary key or throw an exception.
*
* @param mixed $id
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
* @static
*/
public static function findOrFail($id, $columns = array())
{
return \Illuminate\Database\Eloquent\Builder::findOrFail($id, $columns);
}
示例4: find
/**
* Find data by id
*
* @param $id
* @param array $columns
* @return mixed|Model
*/
public function find($id, $columns = ['*'])
{
return $this->wrap(function ($id, $columns = ['*']) {
return $this->model->findOrFail($id, $columns);
}, new Action(__METHOD__, func_get_args(), Action::READ));
}
示例5: find
/**
* Get the specified model record from the database
*
* @param $id
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function find($id)
{
$this->unsetClauses();
$this->newQuery()->eagerLoad();
return $this->query->findOrFail($id);
}
示例6: findOrFail
/**
* @param $id
* @return \Illuminate\Database\Eloquent\Collection|Model
*/
public function findOrFail($id)
{
return $this->query->findOrFail($id);
}
示例7: findFromQuery
/**
* @param Builder $query
* @param int|string|AbstractModel $item
*
* @return AbstractModel
*/
protected function findFromQuery($query, $item)
{
$columns = ['*'];
// If we have an instance already, return it
if ($item instanceof Model) {
return $item;
}
if ($this->items instanceof BelongsToMany) {
$columns = [$this->items->getRelated()->getTable() . '.*'];
}
// Find by slug
if (!is_array($item)) {
if (!preg_match('/^[0-9]+$/', (string) $item) && $this->getModelInstance()->hasTrait('Cviebrock\\EloquentSluggable\\SluggableTrait')) {
return $query->whereSlug($item)->firstOrFail();
}
}
return $query->findOrFail($item, $columns);
}