Skip to content

Commit

Permalink
Add ability to disable touching of parent when toggling relation (#15…
Browse files Browse the repository at this point in the history
…263)
  • Loading branch information
Anahkiasen authored and taylorotwell committed Sep 9, 2016
1 parent 7c83584 commit 119b1e8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,10 @@ public function createMany(array $records, array $joinings = [])
* Each existing model is detached, and non existing ones are attached.
*
* @param mixed $ids
* @param bool $touch
* @return array
*/
public function toggle($ids)
public function toggle($ids, $touch = true)
{
$changes = [
'attached' => [], 'detached' => [],
Expand Down Expand Up @@ -849,7 +850,7 @@ public function toggle($ids)
$changes['attached'] = array_keys($attach);
}

if (count($changes['attached']) || count($changes['detached'])) {
if ($touch && (count($changes['attached']) || count($changes['detached']))) {
$this->touchIfTouching();
}

Expand Down

0 comments on commit 119b1e8

Please sign in to comment.