Open flugg opened 6 years ago
Do you have any estimates when this might be implemented?
Not really, but a bit bummed I haven't had much time to develop this package further the past year. It's in a good state with few bugs, but there are a few of these features I would love to get realised. I'll try my best to get some quality open source time during the summer :)
One of the distinct features of Laravel 5.5 API resources is the ability to use conditional attributes: https://laravel.com/docs/5.5/eloquent-resources#conditional-attributes.
For simple
when
andmergeWhen
this is simply to avoid if-clauses and makes the code more readable. However, thewhenLoaded
provides additional functionality. There's also awhenPivotLoaded
, but I believe awhenIncludedBy
(orwhenLoadedBy
to be consistent?) can be a nice addition as you can add data only when a relation has been included by a specific transformer:You will also get access to the parent data.
I think the best way to implement this is to run an
array_walk_recursive
on the transformed result and replace any placeholder classes with the actual data. It should be looked into how much this affects the performance though.