File tree 1 file changed +17
-8
lines changed
src/Illuminate/Database/Eloquent
1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -126,20 +126,29 @@ public function create(array $attributes = [])
126
126
$ results = $ this ->make ($ attributes );
127
127
128
128
if ($ results instanceof Model) {
129
- $ results ->setConnection ($ results ->query ()->getConnection ()->getName ());
130
-
131
- $ results ->save ();
129
+ $ this ->store (collect ([$ results ]));
132
130
} else {
133
- $ results ->each (function ($ model ) {
134
- $ model ->setConnection ($ model ->query ()->getConnection ()->getName ());
135
-
136
- $ model ->save ();
137
- });
131
+ $ this ->store ($ results );
138
132
}
139
133
140
134
return $ results ;
141
135
}
142
136
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
+
143
152
/**
144
153
* Create a collection of models.
145
154
*
You can’t perform that action at this time.
0 commit comments