From 7f6026295255acc861fa24d500c3213bd8cee607 Mon Sep 17 00:00:00 2001 From: Volodya Kurshudyan <70023120+Volodya995@users.noreply.github.com> Date: Tue, 24 Jan 2023 20:50:24 +0400 Subject: [PATCH] [9.x] Add createQuietly to HasOneOrMany (#45783) Co-authored-by: Valodia --- .../Database/Eloquent/Relations/HasOneOrMany.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php index d1a76c1829f7..17ec20a36206 100755 --- a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php @@ -323,6 +323,17 @@ public function create(array $attributes = []) }); } + /** + * Create a new instance of the related model without raising any events to the parent model. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function createQuietly(array $attributes = []) + { + return Model::withoutEvents(fn () => $this->create($attributes)); + } + /** * Create a new instance of the related model. Allow mass-assignment. *