public function save(Model $model) { $model->save(); $this->attach($model); return $model; }
/** * Detaches a child model from this model. * * @param Model $model child model * * @return self */ public function detach(Model $model) { $model->{$this->foreignKey} = null; $model->save(); return $this; }
/** * Attaches a child model to this model. * * @param Model $model child model * * @return self */ public function attach(Model $model) { $model->{$this->foreignKey} = $this->localModel->{$this->localKey}; $model->save(); return $this; }