Open IlCallo opened 6 years ago
I'll tinker some with polymorphic relations when I have time and see how possible something like this would be to implement.
Thank you :)
+1 :)
any ideas / updates on this?
Not yet, unfortunately :(
Have had limited time to work on open source the last months, but should have some time to work on this and other package-related stuff over Christmas!
Sorry to be pain in the ass, but any updates on this? π
Youβre not a pain in the ass π just been busy with work lately, but will make sure to put this on the top of the priority list!
Hey, gentle bump on this feature, how's it coming along?
π π
Sorry for this taking a long time - I'm almost done with a new major version of the package which swaps out Fractal for API resources. I'll ensure the new version has a good solution for polymorphic relations!
Any updates with the new major version? π
It's technically finished, just missing some tests and documentation!
The more I've worked on it the more I've realised I want to keep the feature set at a minimum. Currently I've replaced Fractal's Serializers with a new Formatter concept. However, since Transformers are replaced with Laravel's API Resources I've removed things like with
and only
since they would require changes to the resource classes themselves which I feel goes outside the scope of the package. That means this issue is no longer part of the responsibilities of this package. Instead I'm working on a new package which handles requests and can do filtering, inclusion of relations and sorting.
I've held back a bit on the major version because I didn't really have a good replacement for the features which are getting removed. With that being said I feel like the new version is a big improvement from the current version and even though it does a bit less things than before it does these things better.
I can push the new version up to a new branch if you (or anybody else) want to check it out and provide feedback?
Would be nice to be able test if and provide some feedback also!
For me (and also our projects) the ?with=xxx
feature has been one of the most used features
Yeah, I feel you and I've used this feature a lot myself. Basically, I would like to have possibilities to not only include relations and filter fields with query parameters, but also query a list of data, sort the data and more. If I were to include all of these features to this package I feel the scope would be very broad and the documentation a bit too heavy. And if I were to only keep the inclusion of relations and filtering fields for this package then there would be two packages concerned about parsing the query string which I would like to avoid.
Either ways, I'll think some more about it - I might re-add these features until the new package is released. The new version is released on a new branch now, would love your feedback: https://github.com/flugger/laravel-responder/tree/feature/api-resources (keep in mind the documentation is not done).
I have managed to create a polymorphic fractal transformer. Have a look at https://github.com/yucadoo/polymorphic-fractal
Derived by #84 discussion. The idea is to allow eager loading (via the mapping implemented in 3.0 on both
$relations
and$load
) also on morphable fields.The syntax would be something like
I'm not sure about how it's possible to implement this without knowing the underlying data or having access to the models, but I think that using a full join maybe can be useful to retrieve all different relations of various morphed records.
Or we can allow a more complex definition and then fallback to meaningful defaults as Laravel does
In this way it's possible to add constraints on the eager loading query and load
PizzaTransformer
relations only whenmorphable_type
is equal to "pizzas" (I guess the relation contains the field name of the related morphable and can be retrieved there) and same goes for the other entries. If indexes are not given (so like the first example), the transformer class itself is used to check againstmorphable_type
(because Laravel by default uses the fully qualified names in this cases), unless a morphable map is defined (check here) and contains a mapping for the Model associated to the transformer, which can usually be retrieved by the Transformer name (App\Transformers\PizzaTransformer
=>Pizza
).Do you think this can be done?