Skip to content

Commit 4517a94

Browse files
committed
- fix appends
1 parent 2855bff commit 4517a94

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: src/QueryBuilder.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ protected function getFieldAppends()
184184
}
185185

186186
$fields = array_map([Str::class, 'snake'], $fields);
187-
if ($tableName == $subjectTable) {
187+
188+
if ($tableName == $subjectTable || $tableName == '_') {
188189
return $this->retrieveFieldsToAppends($fields);
189190
}
190191

@@ -238,6 +239,7 @@ protected function getAllAppends(): array
238239
$request_appends = $this->request->has('append') ? $this->request->appends()->toArray()
239240
: ($this->allowedAppends ? $this->allowedAppends->all() : []);
240241

242+
241243
$fields = array_merge($request_appends, $this->getFieldAppends());
242244
$this->allAppends = collect($fields)->intersect($this->allowedAppends)->values()->all();
243245
}

Diff for: tests/Feature/ApiControllerTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,24 @@ public function it_can_list_only_specific_api_model_fields(): void
130130
'slug' => 'orange',
131131
]);
132132
}
133+
134+
/** @test */
135+
public function it_can_load_api_model_appends_from_fields_even_if_appends_is_blank(): void
136+
{
137+
$this->withoutExceptionHandling();
138+
139+
$product = Product::factory()->create([
140+
'name' => 'Apple',
141+
'slug' => 'orange',
142+
]);
143+
144+
$this->getJson('/products?fields=id,formatted_name&append=')
145+
->assertSuccessful()
146+
->assertJsonFragment([
147+
'formatted_name' => 'Formatted Apple',
148+
])
149+
->assertJsonMissing([
150+
'slug' => 'orange',
151+
]);
152+
}
133153
}

0 commit comments

Comments
 (0)