/** * 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; }