Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Rules/Search/SearchInclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public function buildValidationRules(string $attribute, mixed $value): array
'required',
(new ResourceRelationOrNested())->setResource($this->resource),
],
$attribute.'.includes' => [
'prohibited',
],
$attribute.'.text' => [
'prohibited',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,62 @@ public function test_getting_a_list_of_resources_including_belongs_to_has_many_r
);
}

public function test_getting_a_list_of_resources_including_belongs_to_has_many_relation_using_nested_include(): void
{
$belongsTo = BelongsToRelationFactory::new()->create();
$matchingModel = ModelFactory::new()
->for($belongsTo)
->create()->fresh();

$matchingModel2 = ModelFactory::new()->create()->fresh();

Gate::policy(Model::class, GreenPolicy::class);
Gate::policy(BelongsToRelation::class, GreenPolicy::class);

$response = $this->post(
'/api/models/search',
[
'search' => [
'includes' => [
[
'relation' => 'belongsToRelation',
'includes' => [
['relation' => 'models'],
],
],
],
],
],
['Accept' => 'application/json']
);

$matchingModelBelongsToRelation = $matchingModel->belongsToRelation;

$this->assertResourcePaginated(
$response,
[$matchingModel, $matchingModel2],
new ModelResource(),
[
[
'belongs_to_relation' => array_merge(
$matchingModelBelongsToRelation
->only((new BelongsToResource())->getFields(app()->make(RestRequest::class))),
[
'models' => $matchingModelBelongsToRelation->models
->map(function ($model) {
return $model->only((new ModelResource())->getFields(app()->make(RestRequest::class)));
})
->toArray(),
]
),
],
[
'belongs_to_relation' => null,
],
]
);
}

public function test_getting_a_list_of_resources_including_distant_relation_with_intermediary_search_query_condition(): void
{
$matchingModel = ModelFactory::new()->create(
Expand Down