laravel-orion
laravel-orion copied to clipboard
Creating relation alongside model resource
First of all I would like to thank you tailflow team to create such a nice and wonder full package for Laravel Community. I just want to know How can I create resource with relational data. For Example. Product -> hasMany -> ProductVariant -> I want to create single API point to create Product with ProductVariant then how can I do it?
https://tailflow.github.io/laravel-orion-docs/v2.x/guide/query-parameters.html#including-relations
@jeroenqui i guess that is for GET API.
Hi @atapatel,
At this point, it is not possible to create both model and relation resource in one query. It is possible, however, to do that in two queries, but you would need both model and relation controllers in place.
Another option would be to utilize afterStore
hook on a model controller and write the storing logic for a relation there, but that kind of breaks the whole point of Orion, since you would need to write all that basic stuff all over again.
@alexzarbn I agree code will be duplicated :)
@alexzarbn Any updates on this? Because this is most common requirement in API development.
@alexzarbn any chance to get this feature added?