@@ -32,9 +32,10 @@ public function getTable()
3232 return $ this ->table ;
3333 }
3434
35- protected function value (): Attribute
35+ protected function rawValue (): Attribute
3636 {
3737 return Attribute::get (function ($ value ) {
38+ $ value ??= $ this ->getAttribute ('value ' );
3839 $ class = config ('rapidez.attribute-models ' )[$ this ->backend_model ] ?? null ;
3940
4041 if ($ class ) {
@@ -47,38 +48,36 @@ protected function value(): Attribute
4748 });
4849 }
4950
50- // TODO: Maybe rename this? As this value is mostly used.
51- // And maybe add the option value keys in the array?
52- protected function transformedValue (): Attribute
51+ protected function value (): Attribute
5352 {
54- return Attribute::get (function () {
53+ return Attribute::get (function ($ value ) {
5554 if ($ this ->frontend_input === 'select ' || $ this ->frontend_input === 'multiselect ' ) {
56- if (is_iterable ($ this -> value )) {
55+ if (is_iterable ($ value )) {
5756 return Arr::map (
58- iterator_to_array ($ this -> value ),
57+ iterator_to_array ($ value ),
5958 fn ($ value ) => $ this ->options [$ value ]?->value ?? $ value ,
6059 );
6160 }
6261
63- return $ this ->options [$ this -> value ]?->value ?? $ this -> value ;
62+ return $ this ->options [$ value ]?->value ?? $ value ;
6463 }
6564
66- return $ this -> value ;
65+ return $ value ;
6766 });
6867 }
6968
7069 protected function label (): Attribute
7170 {
7271 return Attribute::get (function () {
73- return is_iterable ($ this ->transformedValue )
74- ? implode (', ' , iterator_to_array ($ this ->transformedValue ))
75- : $ this ->transformedValue ;
72+ return is_iterable ($ this ->value )
73+ ? implode (', ' , iterator_to_array ($ this ->value ))
74+ : $ this ->value ;
7675 });
7776 }
7877
7978 protected function sortOrder (): Attribute
8079 {
81- return Attribute::get (fn () => $ this ->options [$ this ->value ]->sort_order ?? null );
80+ return Attribute::get (fn () => $ this ->options [$ this ->rawValue ]->sort_order ?? null );
8281 }
8382
8483 public function __toString (): string
0 commit comments