From 65100737dacc4c4b42b5699c09680f92dd969b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?= Date: Wed, 29 Mar 2023 09:59:59 -0300 Subject: [PATCH] [10.x] Move SetUniqueIds to run before the creating event (#46622) * Move SetUniqueIds to run before the creating event This fixes a BC caused by PR #46161 * Update Model.php --- src/Illuminate/Database/Eloquent/Model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index d1f019b39f4c..ef5e1faabc99 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1276,6 +1276,10 @@ protected function getKeyForSaveQuery() */ protected function performInsert(Builder $query) { + if ($this->usesUniqueIds()) { + $this->setUniqueIds(); + } + if ($this->fireModelEvent('creating') === false) { return false; } @@ -1287,10 +1291,6 @@ protected function performInsert(Builder $query) $this->updateTimestamps(); } - if ($this->usesUniqueIds()) { - $this->setUniqueIds(); - } - // If the model has an incrementing key, we can use the "insertGetId" method on // the query builder, which will give us back the final inserted ID for this // table from the database. Not all tables have to be incrementing though.