本文整理汇总了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);
}
示例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'));
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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`, ',')")]);
}
}
}
示例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;
}
示例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();
}
示例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.'];
}
示例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;
}
示例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;
}
示例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;
}