flugg / laravel-responder

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

I wish there was an *except* method #185

Open nanadjei opened 2 years ago

nanadjei commented 2 years ago

The way "only" is available I wish there was an "except" or "exclude" method as well. That can be handy if you have a large amount of data to return and you can't want to go through the pain of adding all those data just to exclude only one data. Like so;

 return responder()->success(User::all())->only('id', 'name', 'height', 'dob', 'hair_color', 'gender', 'contact', 'email', 'residential_address', 'country_of_residence')->respond();

Then you can;

 return responder()->success(User::all())->exclude('create_at', 'updated_at')->respond();
ezef commented 5 days ago

You can use a Transformer for that, it will not exclude automatically anything, but it will be clearer in the code

 return responder()
 ->success(User::all(), UserTransformer::class)
->respond();