Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 18, 2020
1 parent 5739cd5 commit 49b3ce0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Expand Up @@ -124,20 +124,18 @@ public function sync($ids, $detaching = true)
}

/**
* Sync the intermediate tables with a list of IDs or collection of models with default values.
* Sync the intermediate tables with a list of IDs or collection of models with the given pivot values.
*
* @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $ids
* @param array $values
* @param bool $detaching
* @param array $defaults
* @return array
*/
public function syncWithPivotDefaults($ids, array $defaults, bool $detaching = true)
public function syncWithPivotValues($ids, array $values, bool $detaching = true)
{
$idsWithDefaults = collect($this->parseIds($ids))->mapWithKeys(function ($id) use ($defaults) {
return [$id => $defaults];
});

return $this->sync($idsWithDefaults, $detaching);
return $this->sync(collect($this->parseIds($ids))->mapWithKeys(function ($id) use ($values) {
return [$id => $values];
}), $detaching);
}

/**
Expand Down
Expand Up @@ -101,7 +101,7 @@ public function testSyncWithPivotDefaultsReturnValueType()
$user = BelongsToManySyncTestTestUser::query()->first();
$articleIDs = BelongsToManySyncTestTestArticle::all()->pluck('id')->toArray();

$changes = $user->articles()->syncWithPivotDefaults($articleIDs, ['visible' => true]);
$changes = $user->articles()->syncWithPivotValues($articleIDs, ['visible' => true]);

collect($changes['attached'])->each(function ($id) {
$this->assertSame(gettype($id), (new BelongsToManySyncTestTestArticle)->getKeyType());
Expand Down

0 comments on commit 49b3ce0

Please sign in to comment.