Skip to content

Commit af54a88

Browse files
authored
Fix forceCreate on MorphMany not returning newly created object (#42996)
1 parent db8188e commit af54a88

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public function forceCreate(array $attributes = [])
5757
{
5858
$attributes[$this->getMorphType()] = $this->morphClass;
5959

60-
parent::forceCreate($attributes);
60+
return parent::forceCreate($attributes);
6161
}
6262
}

tests/Database/DatabaseEloquentMorphOneOfManyTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ public function testMorphType()
9797
public function testForceCreateMorphType()
9898
{
9999
$product = MorphOneOfManyTestProduct::create();
100-
$product->states()->forceCreate([
100+
$state = $product->states()->forceCreate([
101101
'state' => 'active',
102102
]);
103+
104+
$this->assertNotNull($state);
103105
$this->assertSame(MorphOneOfManyTestProduct::class, $product->current_state->stateful_type);
104106
}
105107

0 commit comments

Comments
 (0)