File tree Expand file tree Collapse file tree
src/Illuminate/Database/Eloquent Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,20 +126,29 @@ public function create(array $attributes = [])
126126 $ results = $ this ->make ($ attributes );
127127
128128 if ($ results instanceof Model) {
129- $ results ->setConnection ($ results ->query ()->getConnection ()->getName ());
130-
131- $ results ->save ();
129+ $ this ->store (collect ([$ results ]));
132130 } else {
133- $ results ->each (function ($ model ) {
134- $ model ->setConnection ($ model ->query ()->getConnection ()->getName ());
135-
136- $ model ->save ();
137- });
131+ $ this ->store ($ results );
138132 }
139133
140134 return $ results ;
141135 }
142136
137+ /**
138+ * Set the connection name on the results and store them.
139+ *
140+ * @param \Illuminate\Support\Collection $results
141+ * @return void
142+ */
143+ protected function store ($ results )
144+ {
145+ $ results ->each (function ($ model ) {
146+ $ model ->setConnection ($ model ->query ()->getConnection ()->getName ());
147+
148+ $ model ->save ();
149+ });
150+ }
151+
143152 /**
144153 * Create a collection of models.
145154 *
You can’t perform that action at this time.
0 commit comments