getPublicPropertiesDefinedBySubClass() as $key => $value) { if (is_array($value) || $value instanceof Collection) { $instance->$key = static::reindexArrayWithNumericKeysOtherwiseJavaScriptWillMessWithTheOrder($value); } if ($value instanceof EloquentCollection) { // Preserve collection items order by reindexing underlying array. $instance->$key = $value->values(); } } } }