File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,8 @@ protected function getFieldAppends()
184
184
}
185
185
186
186
$ fields = array_map ([Str::class, 'snake ' ], $ fields );
187
- if ($ tableName == $ subjectTable ) {
187
+
188
+ if ($ tableName == $ subjectTable || $ tableName == '_ ' ) {
188
189
return $ this ->retrieveFieldsToAppends ($ fields );
189
190
}
190
191
@@ -238,6 +239,7 @@ protected function getAllAppends(): array
238
239
$ request_appends = $ this ->request ->has ('append ' ) ? $ this ->request ->appends ()->toArray ()
239
240
: ($ this ->allowedAppends ? $ this ->allowedAppends ->all () : []);
240
241
242
+
241
243
$ fields = array_merge ($ request_appends , $ this ->getFieldAppends ());
242
244
$ this ->allAppends = collect ($ fields )->intersect ($ this ->allowedAppends )->values ()->all ();
243
245
}
Original file line number Diff line number Diff line change @@ -130,4 +130,24 @@ public function it_can_list_only_specific_api_model_fields(): void
130
130
'slug ' => 'orange ' ,
131
131
]);
132
132
}
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
+ }
133
153
}
You can’t perform that action at this time.
0 commit comments