find() public method

Find a model by its primary key.
public find ( mixed $id, array $columns = ['*'] ) : Model | Illuminate\Database\Eloquent\Collection | static[] | static | null
$id mixed
$columns array
return Model | Illuminate\Database\Eloquent\Collection | static[] | static | null
Beispiel #1
0
 /**
  * Update an item
  *
  * @param integer $id
  * @param array   $data
  * @return mixed
  */
 public function update($id, array $data)
 {
     $item = $this->builder->find($id);
     $item->update($data);
     // Reset the query builder
     $this->newBuilder();
     return $item;
 }
 public function findOrFail($id)
 {
     $this->newQuery();
     if ($result = $this->query->find($id)) {
         return $result;
     }
     throw (new ModelNotFoundException())->setModel($this->model);
 }
Beispiel #3
0
 /**
  * Find the token with the given ID, and assert that it has not expired.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param string $id
  * @return static
  * @throws InvalidConfirmationTokenException
  */
 public function scopeValidOrFail($query, $id)
 {
     $token = $query->find($id);
     if (!$token || $token->created_at < new DateTime('-1 day')) {
         throw new InvalidConfirmationTokenException();
     }
     return $token;
 }
Beispiel #4
0
 /**
  * Find a model by its primary key.
  *
  * @param mixed $id
  * @param array $columns
  *
  * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null
  */
 public function find($id, $columns = ['*'])
 {
     if (is_array($id)) {
         return $this->findMany($id, $columns);
     }
     return Cache::tags($this->model->getTable())->remember($id, $this->model->cacheExpiry, function () use($id, $columns) {
         return parent::find($id, $columns);
     });
 }
Beispiel #5
0
 /**
  * @param $id
  * @param array $columns
  * @return mixed
  */
 public function find($id, $columns = array('*'))
 {
     $this->applyCriteria();
     return $this->execute($this->model->find($id, $columns));
 }
Beispiel #6
0
 /**
  * @param $id
  * @param array $columns
  * @return mixed
  */
 public function find($id, $columns = array('*'))
 {
     $this->applyCriteria();
     $this->newQuery()->eagerLoadRelations();
     return $this->model->find($id, $columns);
 }
Beispiel #7
0
 /**
  * Get the specified model record from the database
  *
  * @param $id
  *
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function getById($id)
 {
     $this->unsetClauses();
     $this->newQuery()->eagerLoad();
     return $this->query->find($id);
 }
 /**
  * Find notification by id
  *
  * @param $notification_id
  * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static
  */
 public function find($notification_id)
 {
     return $this->notification->find($notification_id);
 }
 /**
  * @param $id
  * @param array $columns
  * @return mixed
  */
 public function find($id, $columns = array('*'))
 {
     return $this->query->find($id, $columns);
 }
Beispiel #10
0
 /**
  * Find a record
  *
  * @param int   $id
  * @param array $columns
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function find($id, $columns = ['*'])
 {
     return $this->builder->find($id, $columns);
 }
Beispiel #11
0
 /**
  * @param $id
  * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
  */
 public function findById($id)
 {
     return $this->instance->find($id);
 }
 public function find($id)
 {
     return $this->version->find($id);
 }
 /**
  * @param \Illuminate\Database\Eloquent\Builder $builder
  * @param $id
  * @param $status
  *
  * @return bool|int
  */
 private function updateModerationStatus(Builder $builder, $id, $status)
 {
     //If $id parameter is passed then update the specified model
     if ($id) {
         $model = $builder->find($id);
         $model->{$model->getStatusColumn()} = $status;
         $model->{$model->getModeratedAtColumn()} = Carbon::now();
         //if moderated_by in enabled then append it to the update
         if ($moderated_by = $model->getModeratedByColumn()) {
             $model->{$moderated_by} = \Auth::user()->getKey();
         }
         $model->save();
         return $model;
     }
     $update = [$builder->getModel()->getStatusColumn() => $status, $builder->getModel()->getModeratedAtColumn() => Carbon::now()];
     //if moderated_by in enabled then append it to the update
     if ($moderated_by = $builder->getModel()->getModeratedByColumn()) {
         $update[$builder->getModel()->getModeratedByColumn()] = \Auth::user()->getKey();
     }
     return $builder->update($update);
 }
 /**
  * Find an entry.
  *
  * @param                           $identifier
  * @param  array                    $columns
  * @return Presenter|EntryPresenter
  */
 public function find($identifier, array $columns = ['*'])
 {
     return (new Decorator())->decorate($this->query->find($identifier, $columns));
 }
 /**
  * Find a group by ID
  *
  * @param $group_id
  * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|static
  */
 public function find($group_id)
 {
     return $this->groupModel->find($group_id);
 }
 /**
  * Find data by id
  *
  * @param  mixed $id
  * @param  array $columns
  *
  * @return Model|Collection
  */
 public function find($id, $columns = ['*'])
 {
     $this->newQuery();
     return $this->query->find($id, $columns);
 }
 /**
  * Returns user data by user id
  *
  * @param $id
  * @return \Illuminate\Database\Eloquent\Model|null
  */
 public function getUserData($id)
 {
     return $this->queryBuilder->find($id);
 }
 /**
  * Find record by its primary key.
  *
  * @param int $id
  *
  * @return Model
  */
 public function find($id)
 {
     $this->buildQuery();
     return $this->query->find($id);
 }
Beispiel #19
0
 /**
  * Find By Id.
  *
  * @param $categoryId
  * @return mixed
  */
 public function find($categoryId)
 {
     return $this->categoryModel->find($categoryId);
 }
 /**
  * @param int $id
  *
  * @return Model|null
  */
 public function findById($id)
 {
     return $this->model->find($id);
 }
 /**
  * Add the Reject extension to the builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  *
  * @return void
  */
 protected function addReject(Builder $builder)
 {
     $builder->macro('reject', function (Builder $builder, $id = null) {
         $builder->withAnyStatus();
         //If $id parameter is passed then update the specified model
         if ($id) {
             $model = $builder->find($id);
             $model->{$model->getStatusColumn()} = Status::REJECTED;
             $model->{$model->getModeratedAtColumn()} = Carbon::now();
             return $model->save();
         }
         return $builder->update([$builder->getModel()->getStatusColumn() => Status::REJECTED, $builder->getModel()->getModeratedAtColumn() => Carbon::now()]);
     });
 }
Beispiel #22
0
 /**
  * Find a model by its primary key.
  *
  * @param mixed $id
  * @param array $columns
  * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null 
  * @static 
  */
 public static function find($id, $columns = array())
 {
     return \Illuminate\Database\Eloquent\Builder::find($id, $columns);
 }
 /**
  * Find a model by its primary key.
  *
  * @param  mixed $id
  * @param  array $columns
  * @return \Illuminate\Database\Eloquent\Model|null
  */
 public function find($id, $columns = ['*'])
 {
     $results = $this->model->find($id, $columns);
     $this->reset();
     return $this->hookFind($results);
 }