Below is the situation which I want to solve
I have an Eloquent model which has a related model:
public function option() {
return $this->hasOne('RepairOption', 'repair_item_id');
}
public function setOptionArrayAttribute($values)
{
$this->option->update($values);
}
when I create the model, it does not necessarily have a related model. When I update it, I might add an option, or not.
To solve this problem there we go with generic solution working on all the relation types:
if (count($model->relation))
{
// exists
}
0 Comment(s)