Skip to content

Commit

Permalink
改进BelongsToMany attach方法返回的对象
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed May 29, 2024
1 parent e35f497 commit 47f7e44
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/model/relation/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,11 @@ public function attach($data, array $pivot = [])
->exists(false)
->data([])
->save($pivot);
$result[] = $this->newPivot($pivot);

$result[] = $this->pivot->newInstance($pivot, [
[$this->localKey, '=', $this->parent->getKey(), null],
[$this->foreignKey, '=', $id, null],
]);
}

if (count($result) == 1) {
Expand Down

0 comments on commit 47f7e44

Please sign in to comment.