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


PHP Model::find方法代码示例

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


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

示例1: get

 /**
  * Get an Item from storage with optional relations
  *
  * @param $id
  * @param array $with
  * @return Item
  */
 public function get($id, $with = [])
 {
     if (count($with)) {
         return $this->model->where('id', '=', $id)->with($with)->first();
     }
     return $this->model->find($id);
 }
开发者ID:brycenrogers,项目名称:linken,代码行数:14,代码来源:BaseRepository.php

示例2: update

 public function update(EditRoleRequest $request, $id)
 {
     $role = $this->roleModel->find($id);
     $data = $request->only(['name', 'description']);
     $role->update($data);
     $this->setStatusMessage(trans('aliukevicius/laravelRbac::lang.role.messageUpdated', ['name' => $data['name']]));
     return \Redirect::to($this->getRoleUrl('index'));
 }
开发者ID:aliukevicius,项目名称:laravel-rbac,代码行数:8,代码来源:RoleController.php

示例3: find

 /**
  * Find a record with ID primary key
  *
  * @param $id
  * @param array $columns
  * @return mixed
  * @throws \Exception
  */
 public function find($id, $columns = array('*'))
 {
     //$this->model->find($id, $columns);
     $element = $this->model->find($id, $columns);
     if (is_null($element)) {
         throw new \Exception('Element Not Found');
     }
     return $element;
 }
开发者ID:vnzacky,项目名称:dog,代码行数:17,代码来源:EloquentBaseRepository.php

示例4: getById

 /**
  * Find an entity by id
  *
  * @param int $id
  * @param array|string $with
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function getById($id, array $with = array())
 {
     if (!empty($with)) {
         $query = $this->make($with);
         return $query->find($id);
     } else {
         return $this->model->find($id);
     }
 }
开发者ID:khuesmann,项目名称:artisan-create,代码行数:16,代码来源:AbstractEloquentRepository.php

示例5: update

 /**
  * @param $id
  * @param array $attribute
  */
 public function update($id, array $attribute)
 {
     $object = $this->model->find($id);
     if ($object) {
         $object->fill($attribute);
         return $object->save();
     }
     return false;
 }
开发者ID:ShuvarthiDhar,项目名称:tobacco,代码行数:13,代码来源:BaseRepository.php

示例6: find

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

示例7: get

    public static function get($id)
    {
        $supply = parent::find($id);

        if ($supply == null) {
            return null;
        }

        switch ($supply->type_id) {
            case 1:
                $instance = $supply->warehouse;
                break;
            case 2:
                $instance = $supply->vehicle;
                break;
            case 3:
                $instance = $supply->personal;
                break;
            case 4:
                $instance = $supply->building;
                break;
            case 5:
                $instance = $supply->general;
                break;
            default:
                $instance = null;
        }

        return $instance;
    }
开发者ID:xinray,项目名称:html-css,代码行数:30,代码来源:Supply.php

示例8: find

 /**
  * Factory Methods
  */
 public static function find($id, $columns = array('api_keys.*'))
 {
     if (is_numeric($id)) {
         return parent::find($id, $columns);
     }
     return static::query()->where('api_key', $id)->first($columns);
 }
开发者ID:joshhudnall,项目名称:beancounter,代码行数:10,代码来源:ApiKey.php

示例9: updated

 public function updated(Model $model)
 {
     if ($model->isDirty('parent_id')) {
         /**
          * 同步Original数据,是為了清除parent_id的dirty狀態
          */
         $model->syncOriginal();
         $tableName = $model->getTable();
         $oldNode = $model->getOriginal('node');
         if (0 < $model->parent_id) {
             /**
              * @var Model  $parent
              */
             $parent = $model->find($model->parent_id);
             $model->node = $parent->node . $model->id . self::SEPARATOR;
             $model->save();
             //取出原来的level
             $originalLevel = Cache::pull('node-category-original-level-' . $model->id);
             //计算新level与原来的level的差值
             $i = $model->level - $originalLevel;
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level + {$i}"), 'node' => DB::raw("REPLACE(`node`, '{$oldNode}', '{$model->node}')")]);
         } else {
             //修改為頂級分類
             $model->level = 1;
             $model->node = self::SEPARATOR . $model->id . self::SEPARATOR;
             $model->save();
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level - {$model->level}"), 'node' => DB::raw("CONCAT('{$model->node}', `id`, ',')")]);
         }
     }
 }
开发者ID:vergil-lai,项目名称:node-categoires,代码行数:30,代码来源:Observer.php

示例10: find

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

示例11: findByIdOrAlias

 /**
  * Find by id or alias
  *
  * @param  string $idOrAlias
  * @return Category
  */
 public static function findByIdOrAlias($idOrAlias)
 {
     $category = parent::find($idOrAlias);
     if ($category) {
         return $category;
     }
     return parent::where('alias', $idOrAlias)->first();
 }
开发者ID:toancong,项目名称:laravel-articles,代码行数:14,代码来源:Category.php

示例12: delete

 /**
  * Deletes the project using the given project id.
  * DELETE /api/v1/projects/1/delete
  *
  * @param  integer $projectId Project id to delete.
  *
  * @return array
  */
 public function delete($projectId)
 {
     $project = $this->model->find($projectId);
     if ($project === null) {
         return $this->buildFailedResponse('Could not find project with id of ' . $projectId);
     }
     $project->delete();
     return ['status' => 'success', 'message' => 'Successfully deleted project.'];
 }
开发者ID:continuous-deployment,项目名称:pipes,代码行数:17,代码来源:ProjectsController.php

示例13: retrieveByHash

 /**
  * Retrieve a single model using its hash value
  *
  * @param $hash
  * @return null|Model
  */
 public function retrieveByHash($hash)
 {
     $id = $this->decodeHash($hash);
     if ($id) {
         $key = $this->resourceName . '.hash.' . $hash;
         return $this->cache->remember($key, 10, function () use($id) {
             return $this->model->find($id);
         });
     }
     return null;
 }
开发者ID:srlabs,项目名称:groundwork,代码行数:17,代码来源:BaseRepository.php

示例14: findById

 /**
  * @param $id
  * @param array $with
  * @return \Illuminate\Database\Eloquent\Collection|Model|null|static
  * @throws EntityNotFoundException
  */
 public function findById($id, array $with = [])
 {
     if (isset($with) && !empty($with)) {
         if (!is_array($with)) {
             throw new InvalidArgumentException();
         }
         $model = $this->model->with($with)->find($id);
     } else {
         $model = $this->model->find($id);
     }
     return $model;
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:18,代码来源:BaseRepository.php

示例15: saveEntity

 /**
  * @param Entity $entity
  * @param array  $data
  * @return Entity
  */
 public function saveEntity(Entity $entity, $data = array())
 {
     if ($record = $this->model->find($entity->id())) {
         if (isset($data['updated_at'])) {
             $data['updated_at'] = date("Y-m-d H:i:s");
         }
         $record->update($data);
     } else {
         $record = $this->model->create($data);
         $entity->setId($record->id);
     }
     return $entity;
 }
开发者ID:alistairshaw,项目名称:ambitiousmail-relay,代码行数:18,代码来源:AbstractEloquentRepository.php


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