Skip to content

Commit f7c57c4

Browse files
authored
Added passing loaded relationship to value callback (#50167)
1 parent 500fb9f commit f7c57c4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,17 @@ protected function whenLoaded($relationship, $value = null, $default = null)
266266
return value($default);
267267
}
268268

269+
$loadedValue = $this->resource->{$relationship};
270+
269271
if (func_num_args() === 1) {
270-
return $this->resource->{$relationship};
272+
return $loadedValue;
271273
}
272274

273-
if ($this->resource->{$relationship} === null) {
275+
if ($loadedValue === null) {
274276
return;
275277
}
276278

277-
return value($value);
279+
return value($value, $loadedValue);
278280
}
279281

280282
/**

0 commit comments

Comments
 (0)