From 9a9f59fcc6e7b93465ce9848b52a473477dff64a Mon Sep 17 00:00:00 2001 From: donnysim Date: Tue, 13 Apr 2021 09:19:23 +0300 Subject: [PATCH] refactor: extract attribute getter for insert. --- src/Illuminate/Database/Eloquent/Model.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 245a103bce40..e8dea2327933 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -989,6 +989,16 @@ protected function getKeyForSaveQuery() return $this->original[$this->getKeyName()] ?? $this->getKey(); } + /** + * Get all of the current attributes on the model for insert. + * + * @return array + */ + protected function getAttributesForInsert() + { + return $this->getAttributes(); + } + /** * Perform a model insert operation. * @@ -1011,7 +1021,7 @@ protected function performInsert(Builder $query) // 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. - $attributes = $this->getAttributes(); + $attributes = $this->getAttributesForInsert(); if ($this->getIncrementing()) { $this->insertAndSetId($query, $attributes);