Skip to content

feat: Add exclude functionality to JsonResource#57426

Closed
kalebalebachew wants to merge 1 commit intolaravel:12.xfrom
kalebalebachew:feature/resource-exclude
Closed

feat: Add exclude functionality to JsonResource#57426
kalebalebachew wants to merge 1 commit intolaravel:12.xfrom
kalebalebachew:feature/resource-exclude

Conversation

@kalebalebachew
Copy link

@kalebalebachew kalebalebachew commented Oct 17, 2025

  • Introduced a new protected property $excludes to hold attributes to be excluded from the resource array.
  • Added the except method to allow exclusion of specified attributes, supporting dot notation for nested arrays.
  • Implemented applyExcludes method to remove excluded attributes from the resolved data before returning it.

Example

return (new UserResource($user))
    ->except(['password', 'profile.ssn']);

- Introduced a new protected property `$excludes` to hold attributes to be excluded from the resource array.
- Added the `except` method to allow exclusion of specified attributes, supporting dot notation for nested arrays.
- Implemented `applyExcludes` method to remove excluded attributes from the resolved data before returning it.
@taylorotwell
Copy link
Member

We're going to be re-working resources a bit for Laravel 13 so will consider then.

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

Successfully merging this pull request may close these issues.

3 participants