8000 Add `saveQuietly` convenience methods to relations (#38934) · laravel/framework@5ea1f91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ea1f91

Browse files
authored
Add saveQuietly convenience methods to relations (#38934)
1 parent 8d53ebe commit 5ea1f91

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,21 @@ public function save(Model $model, array $pivotAttributes = [], $touch = true)
11551155
return $model;
11561156
}
11571157

1158+
/**
1159+
* Save a new model without raising any events and attach it to the parent model.
1160+
*
1161+
* @param \Illuminate\Database\Eloquent\Model $model
1162+
* @param array $pivotAttributes
1163+
* @param bool $touch
1164+
* @return \Illuminate\Database\Eloquent\Model
1165+
*/
1166+
public function saveQuietly(Model $model, array $pivotAttributes = [], $touch = true)
1167+
{
1168+
return Model::withoutEvents(function () use ($model, $pivotAttributes, $touch) {
1169+
return $this->save($model, $pivotAttributes, $touch);
1170+
});
1171+
}
1172+
11581173
/**
11591174
* Save an array of new models and attach them to the parent model.
11601175
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ public function save(Model $model)
267267
return $model->save() ? $model : false;
268268
}
269269

270+
/**
271+
* Attach a model instance without raising any events to the parent model.
272+
*
273+
* @param \Illuminate\Database\Eloquent\Model $model
274+
* @return \Illuminate\Database\Eloquent\Model|false
275+
*/
276+
public function saveQuietly(Model $model)
277+
{
278+
return Model::withoutEvents(function () use ($model) {
279+
return $this->save($model);
280+
});
281+
}
282+
270283
/**
271284
* Attach a collection of models to the parent instance.
272285
*

0 commit comments

Comments
 (0)
0