@@ -204,7 +204,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu
204
204
}
205
205
206
206
/**
207
- * Returns the raw values of the current attributes.
207
+ * Returns the values for database of the current attributes.
208
208
*
209
209
* @param bool $onlyChanged If true, only return values that have changed since object creation
210
210
* @param bool $recursive If true, inner entities will be cast as array as well.
@@ -213,41 +213,7 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu
213
213
*/
214
214
public function toRawArray (bool $ onlyChanged = false , bool $ recursive = false ): array
215
215
{
216
- $ return = [];
217
-
218
- if (! $ onlyChanged ) {
219
- if ($ recursive ) {
220
- return array_map (static function ($ value ) use ($ onlyChanged , $ recursive ) {
221
- if ($ value instanceof self) {
222
- $ value = $ value ->toRawArray ($ onlyChanged , $ recursive );
223
- } elseif (is_callable ([$ value , 'toRawArray ' ])) {
224
- $ value = $ value ->toRawArray ();
225
- }
226
-
227
- return $ value ;
228
- }, $ this ->attributes );
229
- }
230
-
231
- return $ this ->attributes ;
232
- }
233
-
234
- foreach ($ this ->attributes as $ key => $ value ) {
235
- if (! $ this ->hasChanged ($ key )) {
236
- continue ;
237
- }
238
-
239
- if ($ recursive ) {
240
- if ($ value instanceof self) {
241
- $ value = $ value ->toRawArray ($ onlyChanged , $ recursive );
242
- } elseif (is_callable ([$ value , 'toRawArray ' ])) {
243
- $ value = $ value ->toRawArray ();
244
- }
245
- }
246
-
247
- $ return [$ key ] = $ value ;
248
- }
249
-
250
- return $ return ;
216
+ return $ this ->toDatabase ($ onlyChanged , $ recursive );
251
217
}
252
218
253
219
/**
0 commit comments