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

Eloquent API Resource with loaded relation #642

Closed
jrglaber opened this issue Nov 8, 2019 · 4 comments
Closed

Eloquent API Resource with loaded relation #642

jrglaber opened this issue Nov 8, 2019 · 4 comments
Labels
next Relevant for the next major release

Comments

@jrglaber
Copy link

jrglaber commented Nov 8, 2019

I used the whenLoaded for load the relation in Resources, but the apidoc:generate don't load the relations and don't load the resource correctly:

return [ 'id' => $this->id, 'contacts' => $this->whenLoaded('contacts', function(){ return ContactResource::collection($this->contacts); }), ];

@shalvah
Copy link
Contributor

shalvah commented Jan 11, 2020

What strategy are you using? The Api Resource strategy does not execute your code, and so does not know of those conditions.

@shalvah shalvah closed this as completed Jan 11, 2020
@shalvah shalvah reopened this Jan 11, 2020
@shalvah
Copy link
Contributor

shalvah commented Jan 11, 2020

We could potentially add a with parameter to the annotation. Something like @apiResource App\User with=contacts,pets to indicate that the model should be loaded with those relations. However, depending on how the model instance is generated (see second paragraph in https://laravel-apidoc-generator.readthedocs.io/en/latest/documenting.html#apiresource-apiresourcecollection-and-apiresourcemodel), this may not be guaranteed. It's not a priority now, though. PRs welcome.

@jrglaber
Copy link
Author

awaiting, thanks

@shalvah
Copy link
Contributor

shalvah commented May 7, 2020

This is now supported in Scribe 🙂.

@shalvah shalvah closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next Relevant for the next major release
Projects
None yet
Development

No branches or pull requests

2 participants