diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 89dc62de9471..3f32ae5caec8 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1017,6 +1017,17 @@ public function forceCreate(array $attributes) }); } + /** + * Save a new model instance with mass assignment without raising model events. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model|$this + */ + public function forceCreateQuietly(array $attributes = []) + { + return Model::withoutEvents(fn () => $this->forceCreate($attributes)); + } + /** * Update records in the database. * diff --git a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php index 64827357f44e..488d966ef112 100755 --- a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php @@ -350,6 +350,17 @@ public function forceCreate(array $attributes = []) return $this->related->forceCreate($attributes); } + /** + * Create a new instance of the related model with mass assignment without raising model events. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function forceCreateQuietly(array $attributes = []) + { + return Model::withoutEvents(fn () => $this->forceCreate($attributes)); + } + /** * Create a Collection of new instances of the related model. * diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphMany.php b/src/Illuminate/Database/Eloquent/Relations/MorphMany.php index ada088930855..3636f25d06c2 100755 --- a/src/Illuminate/Database/Eloquent/Relations/MorphMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphMany.php @@ -3,6 +3,7 @@ namespace Illuminate\Database\Eloquent\Relations; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; class MorphMany extends MorphOneOrMany { @@ -75,4 +76,15 @@ public function forceCreate(array $attributes = []) return parent::forceCreate($attributes); } + + /** + * Create a new instance of the related model with mass assignment without raising model events. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function forceCreateQuietly(array $attributes = []) + { + return Model::withoutEvents(fn () => $this->forceCreate($attributes)); + } }