Skip to content

Commit f8c6360

Browse files
authored
[10.x] Fix whenAggregated when default is not specified (#49521)
* Fix: whenAggregated should return MissingValue when default is not specified * Test: whenAggregated should return MissingValue when default is not specified
1 parent a5f661f commit f8c6360

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ public function whenCounted($relationship, $value = null, $default = null)
320320
*/
321321
public function whenAggregated($relationship, $column, $aggregate, $value = null, $default = null)
322322
{
323+
if (func_num_args() < 5) {
324+
$default = new MissingValue;
325+
}
326+
323327
$attribute = (string) Str::of($relationship)->snake()->append('_')->append($aggregate)->append('_')->finish($column);
324328

325329
if (! isset($this->resource->getAttributes()[$attribute])) {

tests/Integration/Http/ResourceTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ public function testResourcesMayHaveOptionalRelationshipAggregates()
502502
'data' => [
503503
'id' => 5,
504504
'title' => 'Test Title',
505-
'average_rating' => null,
506-
'minimum_rating' => null,
507505
'maximum_rating' => 'Default Value',
508506
],
509507
]);

0 commit comments

Comments
 (0)