@@ -107,6 +107,8 @@ class Field extends OrganicField implements JsonSerializable
107107 */
108108 public $ afterUpdateCallback ;
109109
110+ public $ label ;
111+
110112 /**
111113 * Create a new field.
112114 *
@@ -117,6 +119,8 @@ public function __construct($attribute, callable $resolveCallback = null)
117119 {
118120 $ this ->attribute = $ attribute ;
119121
122+ $ this ->label = $ attribute ;
123+
120124 $ this ->resolveCallback = $ resolveCallback ;
121125
122126 $ this ->default (null );
@@ -313,7 +317,7 @@ public function resolveForShow($repository, $attribute = null)
313317 return ;
314318 }
315319
316- if (! $ this ->showCallback ) {
320+ if (!$ this ->showCallback ) {
317321 $ this ->resolve ($ repository , $ attribute );
318322 } elseif (is_callable ($ this ->showCallback )) {
319323 tap ($ this ->value ?? $ this ->resolveAttribute ($ repository , $ attribute ), function ($ value ) use ($ repository , $ attribute ) {
@@ -336,7 +340,7 @@ public function resolveForIndex($repository, $attribute = null)
336340 return ;
337341 }
338342
339- if (! $ this ->indexCallback ) {
343+ if (!$ this ->indexCallback ) {
340344 $ this ->resolve ($ repository , $ attribute );
341345 } elseif (is_callable ($ this ->indexCallback )) {
342346 tap ($ this ->value ?? $ this ->resolveAttribute ($ repository , $ attribute ), function ($ value ) use ($ repository , $ attribute ) {
@@ -356,7 +360,7 @@ public function resolve($repository, $attribute = null)
356360 return ;
357361 }
358362
359- if (! $ this ->resolveCallback ) {
363+ if (!$ this ->resolveCallback ) {
360364 $ this ->value = $ this ->resolveAttribute ($ repository , $ attribute );
361365 } elseif (is_callable ($ this ->resolveCallback )) {
362366 tap ($ this ->resolveAttribute ($ repository , $ attribute ), function ($ value ) use ($ repository , $ attribute ) {
@@ -388,16 +392,23 @@ public function jsonSerialize()
388392 {
389393 return with (app (RestifyRequest::class), function ($ request ) {
390394 return [
391- 'attribute ' => $ this ->attribute ,
395+ 'attribute ' => $ this ->label ?? $ this -> attribute ,
392396 'value ' => $ this ->resolveDefaultValue ($ request ) ?? $ this ->value ,
393397 ];
394398 });
395399 }
396400
401+ public function label ($ label )
402+ {
403+ $ this ->label = $ label ;
404+
405+ return $ this ;
406+ }
407+
397408 public function serializeToValue ($ request )
398409 {
399410 return [
400- $ this ->attribute => $ this ->resolveDefaultValue ($ request ) ?? $ this ->value ,
411+ $ this ->label ?? $ this -> attribute => $ this ->resolveDefaultValue ($ request ) ?? $ this ->value ,
401412 ];
402413 }
403414
0 commit comments