Skip to content

Commit cc3f090

Browse files
committed
fix forceCreate
1 parent 03106ae commit cc3f090

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ public function addEagerConstraints(array $models)
6767
$this->getRelationQuery()->where($this->morphType, $this->morphClass);
6868
}
6969

70+
/**
71+
* Create a new instance of the related model. Allow mass-assignment.
72+
*
73+
* @param array $attributes
74+
* @return \Illuminate\Database\Eloquent\Model
75+
*/
76+
public function forceCreate(array $attributes = [])
77+
{
78+
$attributes[$this->getForeignKeyName()] = $this->getParentKey();
79+
$attributes[$this->getMorphType()] = $this->morphClass;
80+
81+
return $this->related->forceCreate($attributes);
82+
}
83+
7084
/**
7185
* Set the foreign ID and type for creating a related model.
7286
*

0 commit comments

Comments
 (0)