Skip to content

Commit 246873e

Browse files
[9.x] Added saveManyQuietly to the hasOneOrMany and belongsToMany relations (#44913)
* Added saveManyQuietly to the hasOneOrMany and belongsToMany relations * Update HasOneOrMany.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 008a4dd commit 246873e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,20 @@ public function saveMany($models, array $pivotAttributes = [])
12271227
return $models;
12281228
}
12291229

1230+
/**
1231+
* Save an array of new models without raising any events and attach them to the parent model.
1232+
*
1233+
* @param \Illuminate\Support\Collection|array $models
1234+
* @param array $pivotAttributes
1235+
* @return array
1236+
*/
1237+
public function saveManyQuietly($models, array $pivotAttributes = [])
1238+
{
1239+
return Model::withoutEvents(function () use ($models, $pivotAttributes) {
1240+
return $this->saveMany($models, $pivotAttributes);
1241+
});
1242+
}
1243+
12301244
/**
12311245
* Create a new instance of the related model.
12321246
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ public function saveMany($models)
295295
return $models;
296296
}
297297

298+
/**
299+
* Attach a collection of models to the parent instance without raising any events to the parent model.
300+
*
301+
* @param iterable $models
302+
* @return iterable
303+
*/
304+
public function saveManyQuietly($models)
305+
{
306+
return Model::withoutEvents(function () use ($models) {
307+
return $this->saveMany($models);
308+
});
309+
}
310+
298311
/**
299312
* Create a new instance of the related model.
300313
*

0 commit comments

Comments
 (0)