Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15516d5

Browse files
committed
Add internal mapping for custom update fields
1 parent80dc21a commit15516d5

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

‎src/Lodash/Http/Resources/TransformsData.php‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
useLogicException;
88
useLongman\LaravelLodash\Support\Str;
99

10+
usefunctionarray_replace;
1011
usefunctioncall_user_func_array;
1112
usefunctionin_array;
1213
usefunctionis_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 fromthedatabase,
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,themodel's method will be used.
2425
*/
2526
protectedstaticarray$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+
protectedstaticarray$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 fromthedatabase.
3037
*/
3138
protectedstaticarray$hideInOutput = [];
3239

@@ -35,6 +42,11 @@ public static function getTransformFields(): array
3542
returnstatic::$transformMapping;
3643
}
3744

45+
publicstaticfunctiongetInternalFields():array
46+
{
47+
returnstatic::$internalMapping;
48+
}
49+
3850
publicstaticfunctiongetHideInOutput():array
3951
{
4052
returnstatic::$hideInOutput;
@@ -65,8 +77,11 @@ public static function transformToApi(TransformableContract $model): array
6577

6678
publicstaticfunctiontransformToInternal(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 ($transformFieldsas$key =>$transformField) {
7085
if (is_array($transformField)) {
7186
$modelTransformedFields[key($transformField)] =$key;
7287
}else {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp