Inheritance: implements ArrayAcces\ArrayAccess, implements Illuminate\Support\Contracts\ArrayableInterface, implements Illuminate\Support\Contracts\JsonableInterface
示例#1
0
 /**
  * Get the hydrated models without eager loading.
  *
  * @param  array  $columns
  * @return array
  */
 public function getModels($columns = array())
 {
     // First, we will simply get the raw results from the query builders which we
     // can use to populate an array with models. We will pass columns
     // that should be selected as well, which are typically just everything.
     $results = $this->query->get($columns);
     if ($this->total) {
         $this->total = $results->countAll();
     }
     $connection = $this->model->getConnectionName();
     $models = array();
     // Once we have the results, we can spin through them and instantiate a fresh
     // model instance for each records we retrieved from the database. We will
     // also set the proper connection name for the model after we create it.
     foreach ($results as $result) {
         $models[] = $model = $this->model->newFromBuilder($result);
         $model->setConnection($connection);
     }
     return $models;
 }
示例#2
0
 /**
  * Get the name of the related model's "updated at" column.
  *
  * @return string
  */
 public function relatedUpdatedAt()
 {
     return $this->related->getUpdatedAtColumn();
 }
示例#3
0
 /**
  * Save a new model and attach it to the parent model.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Model
  */
 public function save(Model $model)
 {
     $model->save();
     $this->attach($model);
     return $model;
 }
示例#4
0
 /**
  * Associate the model instance to the given parent.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Model
  */
 public function associate(Model $model)
 {
     $this->parent->setAttribute($this->foreignKey, $model->getKey());
     return $this->parent->setRelation($this->relation, $model);
 }
 /**
  * Saves the model instance to database. If necessary, it will purge the model attributes
  * of unnecessary fields. It will also replace plain-text password fields with their hashes.
  *
  * @param array $options
  * @return bool
  */
 protected function performSave(array $options)
 {
     if ($this->autoPurgeRedundantAttributes) {
         $this->attributes = $this->purgeArray($this->attributes);
     }
     if ($this->autoHashPasswordAttributes) {
         $this->attributes = $this->hashPasswordAttributes($this->attributes, static::$passwordAttributes);
     }
     return parent::save($options);
 }
示例#6
0
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     Model::setConnectionResolver($this->app['lmongo']);
     Model::setEventDispatcher($this->app['events']);
 }
示例#7
0
 /**
  * Attach a model instance to the parent model.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->foreignKey, new MongoID($this->parent->getKey()));
     return $model->save() ? $model : false;
 }
示例#8
0
 /**
  * Set a model instance for the model being queried.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Builder
  */
 public function setModel(Model $model)
 {
     $this->model = $model;
     $this->query->collection($model->getCollection());
     return $this;
 }
示例#9
0
 /**
  * Attach a model instance to the parent model.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->morphType, $this->morphClass);
     return parent::save($model);
 }
示例#10
0
 /**
  * Get the name of the "updated at" column.
  *
  * @return string
  */
 public function updatedAt()
 {
     return $this->parent->getUpdatedAtColumn();
 }