Find an entity by it's primary key.

@param int   $id
@param array $attributes

@return \Illuminate\Database\Eloquent\Model
766140
public function find($id, $attributes = ['*'])
    {
        return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($id, $attributes) {
            return $this->prepareQuery($this->createModel())->find($id, $attributes);
        });
    }
12644
private function sync($id, $attributes)
    {
        // Return if the ID is invalid, or attributes is not an array
        if (!isset($id) || !isset($attributes) || empty($attributes)) {
            return $this;
        }

        // Return if there are no relationships of that type
        if (!isset($this->relationships['belongsToMany']) || empty($this->relationships['belongsToMany'])) {
            return $this;
        }

        // Sync each relationship
        foreach ($this->relationships['belongsToMany'] as $join) {

            // The sync option has to be true, the related attribute an array
            if (isset($join['sync']) && $join['sync'] && isset($attributes[$join['alias']]) && is_array($attributes[$join['alias']])) {

                // Delete old values
                $delete = $this->db()->table($join['pivot'])->where($join['localKey'], $id, '=')->delete();

                // Insert new values
                foreach ($attributes[$join['alias']] as $value) {
                    $this->db()->table($join['pivot'])->insert([$join['localKey'] => $id, $join['foreignKey'] => $value]);
                }
            }
        }

        // Return model instance
        return $this;
    }
918694
public function getById($id)
    {
        $id = (int) $id;
        $rowSet = $this->getTableGateway()->select([$this->getPrimaryKey() => $id]);
        $row = $rowSet->current();
        return $row;
    }
457070
protected function _getById($id) {
		$model = $this->_config['model'];
		return $model::find('first', ['conditions' => [$model::key() => $id]]);
	}
515159
public function find($id, $columns = ['*'])
    {
        if (is_array($id) || $id instanceof Arrayable) {
            return $this->findMany($id, $columns);
        }

        return $this->whereKey($id)->first($columns);
    }
584376
protected function search( $id = null, $attributes = array() )
    {
        $globArr = explode( "-", $this->generateIdentifier( $id, $attributes ), 2 );
        if ( sizeof( $globArr ) > 1 )
        {
            $glob = $globArr[0]  . "-" . strtr( $globArr[1], array( '-' => '*', '.' => '*' ) );
        }
        else
        {
            $glob = strtr( $globArr[0], array( '-' => '*', '.' => '*' ) );
        }
        $glob = ( $id === null ? '*' : '' ) . $glob;
        return $this->searchRecursive( $glob, $this->properties['location'] );
    }
993938
public function updateOrCreateNew(array $attributes, $key, array $options = []) : Model
    {
        $query = $this->newQuery();

        if (is_array($key)) {
            foreach ($key as $column) {
                $query->where($column, $attributes[$column]);
            }
        } else {
            $query->where($key, $attributes[$key]);
        }

        /** @var Model|Model $row */
        $row = $query->first();

        if ($row !== null) {
            $row->updateExisting(array_replace($row->getAttributes(), $attributes));

            return $row;
        }

        return $this->fillSave($attributes, $options);
    }
1192333
public function getByID($id)
    {
        $pkey = $this->getPrimaryKey();
        if ($pkey === null)
            throw new DAOException("A primary key is required to select a record by ID");

        // If there's a unary primary key, the value can be specified as a
        // single scalar, rather than an array
        if (count($pkey) === 1 && is_scalar($id))
            foreach ($pkey as $colname => $def)
                $id = [$colname => $id];


        $condition = $this->getSelector($pkey, $id);
        $rec = $this->fetchSingle(QB::where($condition));
        if (empty($rec))
            throw new DAOEXception("Object not found with " . WF::str($id));

        $model = new $this->model_class;
        $model->assignRecord($rec, $this->db);
        return $model;
    }
87943
public function find($id, $columns = ['*'])
    {
        if (Uuid::validate($id)) {
            return $this->findByUuid($id, $columns);
        } else {
            return parent::find($id, $columns);
        }
    }
96072
public static function find($id) 
    {
        self::_checkLoaded();

        $pk               = self::isIgnoringCase() ? strtolower(self::getPK()) : self::getPK();
        $builder          = self::_makeBuilder();
        $builder->fields  = self::extractColumns();
        $builder->where   = self::_extractWhereConditions(array($pk=>$id));
        $builder->limit   = 1;

        $cls  = get_called_class();
        $stmt = self::executePrepared($builder, array($id));
        $data = $stmt->fetch(\PDO::FETCH_ASSOC);

        if (!$data) {
            return null;
        }
        return new $cls($data);
    }
971645
public function detach($id, $relation, $attributes)
    {
        return $this->find($id)->{$relation}()->detach($attributes);
    }
389344
protected function attachUsingCustomClass($id, array $attributes)
    {
        $records = $this->formatAttachRecords(
            $this->parseIds($id), $attributes
        );

        foreach ($records as $record) {
            $this->newPivot($record, false)->save();
        }
    }
478189
public function findById($name, $id) {
        $this->load();
        $mapper = MapperBuilder::buildFromName($this->mapping, $name);

        $newEntity = NULL;

        $query = "SELECT * FROM `" . $mapper->getTable() . "` WHERE id = :id";

        $result = $this->getDataSource()->query($query, array(":id" => $id));

        if ($result) {
            $newEntity = $mapper->createObject($result[0]);

            /* relations */
            foreach ($mapper->getRelations() as $relation) {

                /* only set relations if not lazy */
                if (!$relation->isLazy()) {
                    $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());

                    $queryRel = QueryBuilder::buildSelectRelation($relation, $relMapper);

                    $resRel = $this->getDataSource()->query($queryRel, array(":id" => $newEntity->getId()));

                    $method = "set" . $relation->getName();
                    if ($resRel) {
                        $collection = new Collection($relMapper->getClass(), $resRel, $relMapper);
                    } else {
                        $collection = new Collection($relMapper->getClass(), array(), $relMapper);
                    }
                    $newEntity->$method($collection);
                }
            }
        }
        return $newEntity;
    }
1125262
public function findById($class, $id) {
        $mapper = MapperBuilder::buildFromMapping($this->mapping, $class);

        $newEntity = NULL;

        $query = "SELECT * FROM `" . $mapper->getTable() . "` WHERE id='$id'";
        $result = $this->conn->executeQuery($query);

        if ($result) {
            $class = $mapper->getClass();
            $newEntity = new $class();
            $this->populateEntity($newEntity, $result[0], $mapper);

            // populate relations
            foreach ($mapper->getRelations() as $relation) {

                $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
                $queryRel = $this->buildSelectRelation($newEntity, $mapper, $relation, $relMapper);
                $resRel = $this->conn->executeQuery($queryRel);

                $classRel = $relMapper->getClass();
                $method = "set" . $relation->getName();
                if ($resRel) {
                    foreach ($resRel as $row) {
                        $newEntityRel = new $classRel();
                        $this->populateEntity($newEntityRel, $row, $relMapper, $relation->getForeignColumn());
                        $array[] = $newEntityRel;
                    }
                    $newEntity->$method($array);
                }
            }
        }
        return $newEntity;
    }
1314262
public function save(Entity $entity, $attributes = array())
    {
        foreach ($attributes as $key => $value) {
            $entity->$key = $value;
        }

        // when new record.
        if ($entity->isNew()) {
            $new = $this->create($entity->toArray());
            $entity->exists = true;
            $entity->setPrimaryValue($new->getPrimaryValue());
        }

        // when update.
        else {
            $attributes = $entity->getAttributes(true);
            if (! $attributes ) return;

            return $this->update($attributes, $entity->getPrimaryValue());
        }
    }
778806
private function processBeginCache($id,$attributes,$offset)
	{
		$attrs=$this->processAttributes($attributes);
		if(empty($attrs))
			return $this->generatePhpCode("if(\$this->beginCache('$id')):",$offset);
		else
			return $this->generatePhpCode("if(\$this->beginCache('$id', array($attrs))):",$offset);
	}
916909
public function findById($id)
    {
        $query =
            'SELECT `' .
            $this->getFields("`, `") . '`
            FROM ' . $this->tableName .
            ' WHERE `id`=:id LIMIT 1';
        $statement = $this->database->prepare($query);
        $statement->bindParam(':id', $id);
        $statement->execute();
        $this->entity->fill($statement->fetch());
        return $this->entity;
    }