當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。