0

I am using apiato framework,i am developing one API which is responsible for retrieving the data from the database upto this part is working ,Now i want to resolve the N+1 Query problem for that i am using eager loading concept and andersao/l5-repository it's dealing with() fn .when ever i use l5-repository concept i removed defaultIncludes Array from transformer it's not retrieving data with relations,can you please help me to fix this issue

Normal URL when ever defaultIncludes Array available : v1/users it's working fine it's retrieving data from DB(users & subscriptions details).

when ever i use eagerLoading and l5-reposiry concept : v1/users?with=subscription it's not retrieving subscriptions (only Usres).

GetAllUsersRequest.php

  public function prepareForValidation()
    {
        request()->request->add(['with' => 'subscription']);
        request()->query->add(['with' => 'subscription']);
    }

UsersTransformer.php

public defaultIncludes=['subscription'];

1 Answers1

0

You have to use eager loading concept in the database queries it's loading the relationships with less time .

https://laravel.com/docs/8.x/eloquent-relationships#eager-loading

Sai Tarun
  • 569
  • 4
  • 14