77use LogicException ;
88use Longman \LaravelLodash \Support \Str ;
99
10+ use function array_replace ;
1011use function call_user_func_array ;
1112use function in_array ;
1213use function is_array ;
@@ -17,16 +18,22 @@ trait TransformsData
1718{
1819/**
1920 * Fields transform mapping.
20- * In array key should be a column name from database,
21+ * In array key should be a column name fromthe database,
2122 * value can be just name (if getter exists for that name, or array [fieldName => getterMethod]).
2223 * If static getterMethod is defined in the resource class, it will be called and as a first argument will be passed TransformableContract $model,
23- * Otherwise, model's method will be used.
24+ * Otherwise,the model's method will be used.
2425 */
2526protected static array $ transformMapping = [];
2627
28+ /**
29+ * Fields list for merging with general mapping during transformation o internal. Used for updating some fields.
30+ * Array values should be a column name from the database.
31+ */
32+ protected static array $ internalMapping = [];
33+
2734/**
2835 * Fields list for hiding in output.
29- * Array values should be a column name from database,
36+ * Array values should be a column name fromthe database.
3037 */
3138protected static array $ hideInOutput = [];
3239
@@ -35,6 +42,11 @@ public static function getTransformFields(): array
3542return static ::$ transformMapping ;
3643 }
3744
45+ public static function getInternalFields ():array
46+ {
47+ return static ::$ internalMapping ;
48+ }
49+
3850public static function getHideInOutput ():array
3951 {
4052return static ::$ hideInOutput ;
@@ -65,8 +77,11 @@ public static function transformToApi(TransformableContract $model): array
6577
6678public static function transformToInternal (array $ fields ):array
6779 {
80+ $ transformFields =static ::getTransformFields ();
81+ $ transformFields =array_replace ($ transformFields ,static ::getInternalFields ());
82+
6883$ modelTransformedFields = [];
69- foreach (static :: getTransformFields () as $ key =>$ transformField ) {
84+ foreach ($ transformFields as $ key =>$ transformField ) {
7085if (is_array ($ transformField )) {
7186$ modelTransformedFields [key ($ transformField )] =$ key ;
7287 }else {