laravel-json-api / laravel

JSON:API for Laravel applications
MIT License
523 stars 43 forks source link

Hiding field using helper method like isViewingOne #253

Closed od3n closed 10 months ago

od3n commented 11 months ago

Is it possible to use that?

I tried both on Schema & Resource but failed. Or I did do it the wrong way?

Currently, I use sparse fields to archive that. fields[user] = name, email

Any suggestion?

lindyhopchris commented 10 months ago

Sorry for taking a while to get back to you about this.

Sparse fieldsets is exactly how this should be done. The aim of the spec is to give the client control of what it wants in the response. The client should be explicit (via sparse fieldsets) about what fields it wants in the response, as only the client knows which fields it is actually going to make use of. The server therefore shouldn't make any decisions about what fields to show, and which ones shouldn't.

I'm going to close this issue as you're actually already doing it right by using sparse fields.