flugg / laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.
MIT License
862 stars 86 forks source link

Filtering from query string - opposite to only #153

Open Hesesses opened 4 years ago

Hesesses commented 4 years ago

Filtering From Query String

Fields will automatically be filtered if the filter_fields_parameter configuration key is set to a string. It defaults to only, allowing you to filter fields from the query string:

GET /products?only=id,name

Would be nice if you could have the opposite for only, for example: ...?hide=id,name ...?except=id,name

And then those fields would be empty when returning the transformer

flugg commented 4 years ago

Agreed that would be nice, however, if I remember correctly Fractal didn't have this feature and the filtering is currently based on their implementation. With that said I started out adding both only and except to the new version, but then removed them as I didn't want the package to be concerned about the query string anymore. Instead I was looking into moving all this logic into a new Laravel Requester or Laravel Inquirer package which handled the parsing of query strings and allowed for filtering fields, querying results, sorting, including relations etc.

Was thinking of creating an issue to discuss this idea further, but would love to hear your initial opinions on it.

Hesesses commented 4 years ago

I always like when things can be splitted to smaller components and if all this logic can be moved to Requester or Inquirer packages, that sounds good if those packages are flexible to work with :)