@@ -116,6 +116,66 @@ private function resolveFields(Resource $resourceInstance): Collection
116
116
117
117
}
118
118
119
+ /**
120
+ * Resolve the field's value for display.
121
+ *
122
+ * @param mixed $resource
123
+ * @param string|null $attribute
124
+ * @return void
125
+ */
126
+ public function resolveForDisplay ($ resource , $ attribute = null )
127
+ {
128
+
129
+ /**
130
+ * @var null|Model $relationInstance
131
+ * @var Field $field
132
+ */
133
+ $ attribute = $ attribute ?? $ this ->attribute ;
134
+
135
+ parent ::resolveForDisplay ($ resource , $ attribute );
136
+
137
+ if ($ relationInstance = $ resource ->$ attribute ) {
138
+
139
+ foreach ($ this ->getFields ($ relationInstance ) as $ field ) {
140
+
141
+ $ field ->resolveForDisplay ($ relationInstance );
142
+
143
+ }
144
+
145
+ }
146
+
147
+ }
148
+
149
+ /**
150
+ * Resolve the field's value.
151
+ *
152
+ * @param mixed $resource
153
+ * @param string|null $attribute
154
+ * @return void
155
+ */
156
+ public function resolve ($ resource , $ attribute = null )
157
+ {
158
+
159
+ /**
160
+ * @var null|Model $relationInstance
161
+ * @var Field $field
162
+ */
163
+ $ attribute = $ attribute ?? $ this ->attribute ;
164
+
165
+ parent ::resolve ($ resource , $ attribute );
166
+
167
+ if ($ relationInstance = $ resource ->$ attribute ) {
168
+
169
+ foreach ($ this ->getFields ($ relationInstance ) as $ field ) {
170
+
171
+ $ field ->resolve ($ relationInstance );
172
+
173
+ }
174
+
175
+ }
176
+
177
+ }
178
+
119
179
/**
120
180
* Resolve the given attribute from the given resource.
121
181
*
@@ -133,10 +193,9 @@ protected function resolveAttribute($resource, $attribute)
133
193
134
194
if ($ relationInstance = $ resource ->$ attribute ) {
135
195
136
- $ fields = $ this ->getFields ($ relationInstance );
137
196
$ resource = Nova::resourceForModel ($ relationInstance );
138
197
139
- foreach ($ fields as $ field ) {
198
+ foreach ($ this -> getFields ( $ relationInstance ) as $ field ) {
140
199
141
200
if ($ field instanceof HasOne ||
142
201
$ field instanceof HasMany ||
@@ -149,8 +208,6 @@ protected function resolveAttribute($resource, $attribute)
149
208
150
209
}
151
210
152
- $ field ->resolve ($ relationInstance );
153
-
154
211
}
155
212
156
213
return $ resource ;
0 commit comments