-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Add whenHas
to JsonResource
#45376
[9.x] Add whenHas
to JsonResource
#45376
Conversation
Why can you not just use |
@taylorotwell At some times, the default value is null for example |
If you select |
As for me naming is inconvenient to other Laravel classes. It would be better name it |
This PR adds a
whenHas
method to the JSON resource class giving us the ability to conditionally include attributes in a response when an attribute has in the model.In some time to need to make many resources for return data to API because we do need to return for example in the function index only
id
andname
for the user. But in the show function, you need all data for the user.To fix this problem need to make many resources for resolving it.
And I think all developers need this feature
Note: I make some clear and enhancement
whenCounted
towhenHas
functionBefore:
Now with magic function with the same
Resource
: