Skip to content

[9.x] Add saveQuietly convenience methods to relations #38934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,21 @@ public function save(Model $model, array $pivotAttributes = [], $touch = true)
return $model;
}

/**
* Save a new model without raising any events and attach it to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param array $pivotAttributes
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/
public function saveQuietly(Model $model, array $pivotAttributes = [], $touch = true)
{
return Model::withoutEvents(function () use ($model, $pivotAttributes, $touch) {
return $this->save($model, $pivotAttributes, $touch);
});
}

/**
* Save an array of new models and attach them to the parent model.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ public function save(Model $model)
return $model->save() ? $model : false;
}

/**
* Attach a model instance without raising any events to the parent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Database\Eloquent\Model|false
*/
public function saveQuietly(Model $model)
{
return Model::withoutEvents(function () use ($model) {
return $this->save($model);
});
}

/**
* Attach a collection of models to the parent instance.
*
Expand Down