Skip to content

Commit cde521c

Browse files
committed
fix issue where displayUsing was being ignored for all dependency field
1 parent a904ec5 commit cde521c

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

src/InlineMorphTo.php

+61-4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,66 @@ private function resolveFields(Resource $resourceInstance): Collection
116116

117117
}
118118

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+
119179
/**
120180
* Resolve the given attribute from the given resource.
121181
*
@@ -133,10 +193,9 @@ protected function resolveAttribute($resource, $attribute)
133193

134194
if ($relationInstance = $resource->$attribute) {
135195

136-
$fields = $this->getFields($relationInstance);
137196
$resource = Nova::resourceForModel($relationInstance);
138197

139-
foreach ($fields as $field) {
198+
foreach ($this->getFields($relationInstance) as $field) {
140199

141200
if ($field instanceof HasOne ||
142201
$field instanceof HasMany ||
@@ -149,8 +208,6 @@ protected function resolveAttribute($resource, $attribute)
149208

150209
}
151210

152-
$field->resolve($relationInstance);
153-
154211
}
155212

156213
return $resource;

0 commit comments

Comments
 (0)