Skip to content
Discussion options

You must be logged in to vote

You can call to inheritance.

You have a UserResource which is a full resource. Create a child BriefUserResource with overridden toArray() as (fill free to make a trait):

public function toArray(Request $request): array
{
    return Arr::only(parent::toArray(request), ['id', 'username', 'email']));
}

And instead of UserResource point your ResourceCollection to BriefUserResource:

public $collects = BriefUserResource::class;

No need to override toArray() in your collection.

Next question is why do you even need to populate street, city, country, zipcode, if they wouldn't be needed? And reverse the inheritance.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Floppy012
Comment options

Answer selected by Floppy012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants