Exemple #1
0
 /**
  * Create a new record into the database.
  *
  * @param  array             $attributes attributes
  * @return \Model\Collection
  */
 public function create(array $attributes)
 {
     $model = $this->create_new($attributes);
     $model->save();
     // TODO: dry with 'queryEagerLoadRelations'
     $eagerLoads = $this->query->getEagerLoads();
     if (count($eagerLoads) > 0) {
         $relations = $this->query->eagerLoadRelations(array($model));
         $model = $relations[0];
     }
     return $model;
 }
 /**
  * Create a new record into the database.
  *
  * @param  array             $attributes attributes
  * @return \Model\Collection
  */
 public function create(array $attributes)
 {
     // Is this a bulk create?
     if (array_values($attributes) == $attributes) {
         $that = $this;
         $collection = new IlluminateCollection($attributes);
         return $collection->map(function ($attrs) use($that) {
             return $that->create($attrs);
         });
     }
     $model = $this->create_new($attributes);
     $model->save();
     // TODO: dry with 'queryEagerLoadRelations'
     $eagerLoads = $this->query->getEagerLoads();
     if (count($eagerLoads) > 0) {
         $relations = $this->query->eagerLoadRelations(array($model));
         $model = $relations[0];
     }
     return $model;
 }
Exemple #3
0
 /**
  * Set the relationships that should not be eager loaded.
  *
  * @param  Illuminate\Database\Query\Builder $query
  * @param  mixed $relations
  * @return $this
  */
 public function scopeWithout($query, $relations)
 {
     $relations = is_array($relations) ? $relations : array_slice(func_get_args(), 1);
     $relationships = array_dot($query->getEagerLoads());
     foreach ($relations as $relation) {
         unset($relationships[$relation]);
     }
     return $query->setEagerLoads([])->with(array_keys($relationships));
 }