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


PHP Builder::findOrFail方法代码示例

本文整理汇总了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);
 }
开发者ID:propaganistas,项目名称:laravel-repository,代码行数:22,代码来源:Repository.php

示例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');
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:23,代码来源:CategoryController.php

示例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);
 }
开发者ID:satriashp,项目名称:tour,代码行数:13,代码来源:_ide_helper.php

示例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));
 }
开发者ID:sandeeprajoria,项目名称:Housekeeper,代码行数:13,代码来源:BaseRepository.php

示例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);
 }
开发者ID:Okipa,项目名称:una.app,代码行数:13,代码来源:BaseRepository.php

示例6: findOrFail

 /**
  * @param $id
  * @return \Illuminate\Database\Eloquent\Collection|Model
  */
 public function findOrFail($id)
 {
     return $this->query->findOrFail($id);
 }
开发者ID:gdgfoz,项目名称:codelab-todo-api,代码行数:8,代码来源:BaseRepository.php

示例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);
 }
开发者ID:anahkiasen,项目名称:arrounded,代码行数:24,代码来源:AbstractRepository.php


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