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


PHP Model::findOrFail方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::findOrFail方法的具体用法?PHP Model::findOrFail怎么用?PHP Model::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: find

 /**
  * {@inheritdoc}
  */
 public function find($id)
 {
     try {
         return $this->model->findOrFail($id);
     } catch (ModelNotFoundException $e) {
         throw new EntityNotFoundException("Could not find entity with ID {$id}");
     }
 }
开发者ID:3ev,项目名称:repoman,代码行数:11,代码来源:Repository.php

示例2: update

 /**
  * Update an user.
  *
  * @param  int $id
  * @param  array $data
  * @return \Illuminate\Contracts\Auth\Authenticatable
  */
 public function update($id, array $data)
 {
     if (isset($data['password'])) {
         $data['password'] = bcrypt($data['password']);
     }
     $user = $this->model->findOrFail($id);
     return $user->update($data);
 }
开发者ID:jenky,项目名称:laravel-api-starter,代码行数:15,代码来源:UserRepository.php

示例3: attach

 /**
  * Attach the request data too the model.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int|null $id
  * @param  array $data
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function attach(Request $request, $id = null, array $data = [])
 {
     if (is_numeric($id)) {
         $this->model = $this->model->findOrFail($id);
     }
     $this->handle($request, $data);
     return $this->model;
 }
开发者ID:jenky,项目名称:laravel-api-starter,代码行数:16,代码来源:Manager.php

示例4: update

 /**
  * Update data.
  *
  * @param int $id primary key
  * @param array $data
  *
  * @return Model|bool
  */
 public function update($id, array $data)
 {
     $data = $this->format($data);
     $model = $this->model->findOrFail($id);
     if ($model->update($data)) {
         return $model;
     }
     return false;
 }
开发者ID:bhutanio,项目名称:laravel-utilities,代码行数:17,代码来源:DataService.php

示例5: update

 public function update(Request $request, $id)
 {
     $user = $this->userModel->findOrFail($id);
     $data = ['name' => $request->name, 'email' => $request->email];
     if ($request->has('password')) {
         $data['password'] = bcrypt($request->get('password'));
     }
     $user->update($data);
     $user->roles()->sync($request->get('roles', []));
     return redirect()->back();
 }
开发者ID:cinject,项目名称:admin-panel,代码行数:11,代码来源:UserController.php

示例6: update

 /**
  * Updates an existing record. $id can be a model instance.
  *
  * @param $id
  * @param array $attributes
  * @return mixed
  */
 public function update($id, array $attributes)
 {
     if ($id instanceof Model) {
         return $id->update($attributes);
     }
     return $this->model->findOrFail($id)->update($attributes);
 }
开发者ID:logaretm,项目名称:depo,代码行数:14,代码来源:RepositoryBase.php

示例7: find

 /**
  * Find data by id.
  *
  * @param $id
  * @param array $columns
  *
  * @return mixed
  */
 public function find($id, array $columns = ['*'])
 {
     $this->applyCriteria()->applyOrder();
     $model = $this->model->findOrFail($id, $columns);
     $this->makeModel();
     return $this->parseResult($model);
 }
开发者ID:sjfinder,项目名称:repository,代码行数:15,代码来源:BaseRepository.php

示例8: update

 /** Update the model or models attributes.
  * @param  int|null  $id
  * @param  array  $attributes
  * @throws \Exception  When id is not given
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function update($id, array $attributes)
 {
     $model = $this->model->findOrFail($id);
     $this->validation()->validate('update', array_merge($attributes, [$this->model->getKeyName() => $id]));
     $model->fill($attributes);
     $model->save();
     return $model;
 }
开发者ID:sedp-mis,项目名称:base-repository,代码行数:15,代码来源:BaseRepositoryEloquent.php

示例9: findOrFail

 /**
  * @param $id
  * @return mixed|Exception
  */
 public function findOrFail($id, array $with = array())
 {
     $this->addWithCriteria($with);
     $this->applyCriteria();
     $result = $this->model->findOrFail($id);
     $this->refresh();
     return $result;
 }
开发者ID:ablunier,项目名称:laravel-database,代码行数:12,代码来源:Repository.php

示例10: find

 /**
  * @param $id
  * @param array $columns
  *
  * @return mixed
  */
 public function find($id, $columns = ['*'])
 {
     $this->eagerLoading();
     $this->applyCriteria();
     $results = $this->model->findOrFail($id, $columns);
     $this->resetModel();
     return $this->parseResult($results);
 }
开发者ID:killtw,项目名称:repository,代码行数:14,代码来源:BaseRepository.php

示例11: update

 /**
  * Update a entity in modal by id.
  *
  * @param array $attributes
  * @param $id
  *
  * @throws ValidatorException
  *
  * @return mixed
  */
 public function update(array $attributes, $id)
 {
     $model = $this->model->findOrFail($id);
     $model->fill($attributes);
     $model->save();
     $this->resetModel();
     return $model;
 }
开发者ID:Jastkast,项目名称:Page,代码行数:18,代码来源:BaseRepository.php

示例12: destroyModel

 /**
  * @author WN
  * @param Model $model
  * @param int $id
  * @param string $modelName
  * @param string $redirect
  * @return \Illuminate\Http\RedirectResponse
  * @throws RedirectException
  */
 protected function destroyModel(Model $model, $id, $modelName, $redirect)
 {
     try {
         $model->findOrFail($id);
         $model->destroy($id);
     } catch (ModelNotFoundException $e) {
         $this->logError('Deletion of this record did not complete successfully' . $e->getMessage());
         throw (new RedirectException())->setTarget($redirect)->setError('Deletion of this record did not complete successfully');
     }
     return redirect($redirect)->with('messages', ['success' => ucwords($modelName) . ' was successfully deleted']);
 }
开发者ID:paybreak,项目名称:basket,代码行数:20,代码来源:ModelTrait.php

示例13: show

 /**
  * Returns a single item
  * 
  * @param  mixed $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function show($id)
 {
     try {
         if (is_array($id)) {
             return $this->response->withItem($this->model->where($id)->firstOrFail(), new $this->transformerName());
         } else {
             return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName());
         }
     } catch (ModelNotFoundException $e) {
         return $this->respondNotFound();
     }
 }
开发者ID:ddimaria,项目名称:Laravel-REST-CMS,代码行数:18,代码来源:ApiController.php

示例14: 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

示例15: update

 /**
  * Update a entity in repository by id.
  *
  * @param array $attributes
  * @param $id
  *
  * @return mixed
  */
 public function update(array $attributes, $id)
 {
     $this->applyScope();
     $_skipPresenter = $this->skipPresenter;
     $this->skipPresenter(true);
     $model = $this->model->findOrFail($id);
     $model->fill($attributes);
     $model->save();
     $this->skipPresenter($_skipPresenter);
     $this->resetModel();
     event(new RepositoryEntityUpdated($this, $model));
     return $this->parserResult($model);
 }
开发者ID:LavaLite,项目名称:framework,代码行数:21,代码来源:BaseRepository.php


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