Skip to content

Commit b2f4e38

Browse files
authored
Allow for empty attributes in response (#27)
1 parent ef00368 commit b2f4e38

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/Resources/JsonApiResource.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,18 @@ public function toArray($request): array
8080
public function getResourceData($request): array
8181
{
8282
if (empty($this->data)) {
83-
$this->data = array_filter([
84-
'id' => $this->getId(),
85-
'type' => $this->getType(),
86-
'attributes' => $this->getAttributes($request),
87-
'relationships' => empty($this->relationshipReferences) ? $this->resolveRelationships($request) : $this->relationshipReferences,
88-
'meta' => $this->getMeta($request),
89-
'links' => $this->getLinks($request),
90-
], fn ($value) => ! empty($value));
83+
$this->data = array_filter(
84+
[
85+
'id' => $this->getId(),
86+
'type' => $this->getType(),
87+
'attributes' => $this->getAttributes($request),
88+
'relationships' => empty($this->relationshipReferences) ? $this->resolveRelationships($request) : $this->relationshipReferences,
89+
'meta' => $this->getMeta($request),
90+
'links' => $this->getLinks($request),
91+
],
92+
fn ($value, $key) => $key === 'attributes' || ! empty($value),
93+
ARRAY_FILTER_USE_BOTH
94+
);
9195
}
9296

9397
return $this->data;

0 commit comments

Comments
 (0)