/**
* Removes a model from this relationship type.
*/
public function remove(Model $model, $sessionKey = null)
{
if ($sessionKey === null) {
$options = $this->parent->getRelationDefinition($this->relationName);
if (array_get($options, 'delete', false)) {
$model->delete();
} else {
/*
* Make this model an orphan ;~(
*/
$model->setAttribute($this->getPlainForeignKey(), null);
$model->setAttribute($this->getPlainMorphType(), null);
$model->save();
}
/*
* Use the opportunity to set the relation in memory
*/
if ($this instanceof MorphOne) {
$this->parent->setRelation($this->relationName, null);
} else {
$this->parent->reloadRelations($this->relationName);
}
} else {
$this->parent->unbindDeferred($this->relationName, $model, $sessionKey);
}
}