File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ protected function modifyQuery(\Spatie\QueryBuilder\QueryBuilder $query): \Spati
3131
3232 return $ query ;
3333 }
34+
35+ /**
36+ * Get the index allowed fields
37+ */
38+ public function getIndexAllowedFields (): array
39+ {
40+ return [
41+ 'id ' ,
42+ 'name ' ,
43+ ];
44+ }
45+
3446 /**
3547 * Get the allowed fields
3648 *
Original file line number Diff line number Diff line change @@ -301,4 +301,23 @@ public function it_cannot_include_dynamic_fields_if_required_params_are_missing(
301301 'rating ' => $ product_2 ->id + 10 ,
302302 ]);
303303 }
304+
305+ #[Test]
306+ public function it_does_not_include_fields_that_are_not_allowed (): void
307+ {
308+ $ this ->withoutExceptionHandling ();
309+
310+ $ product_1 = Product::factory ()->create ([
311+ 'name ' => 'Apple ' ,
312+ 'slug ' => 'apple '
313+ ]);
314+
315+ $ this ->getJson ('/products ' )
316+ ->assertJsonMissing ([
317+ 'slug ' => 'apple ' ,
318+ ])
319+ ->assertJsonFragment ([
320+ 'name ' => 'Apple ' ,
321+ ]);
322+ }
304323}
You can’t perform that action at this time.
0 commit comments