Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access loaded relations before those are loaded #156

Open
Hesesses opened this issue Mar 5, 2020 · 1 comment
Open

Access loaded relations before those are loaded #156

Hesesses opened this issue Mar 5, 2020 · 1 comment

Comments

@Hesesses
Copy link

Hesesses commented Mar 5, 2020

Hi,

The title of the issue is superbad, but i try to explain it better here:

I have a http request, lets say GET /teams?with=players
and later on my controller I have:

$teams = $teamsService->getTeams();
return responder()
->success($teams->paginate())
->respond(200);

I would like to use ->meta() to include something related to players:

$teams = $teamsService->getTeams();
return responder()
->success($teams->paginate())
->meta($teamsService->getPlayerMeta($teams))
->respond(200);

function getPlayerMeta($teams) {
   dd($teams); // this only have the array of teams without the ?with=players relation
}

The questions is, is it somehow possible to access the relations that are going to be loaded and use those in ->meta() ?

@flugg
Copy link
Owner

flugg commented Mar 6, 2020

I'm afraid there's currently no way to do this as the relations are kind of hard coded into the last step of the response creation. Luckily this will be possible in the new version though, as all relations will have to be loaded before sending them to the responder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants