laravel-orion icon indicating copy to clipboard operation
laravel-orion copied to clipboard

Creating relation alongside model resource

Open atapatel opened this issue 2 years ago • 6 comments

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?

atapatel avatar Sep 03 '22 06:09 atapatel

https://tailflow.github.io/laravel-orion-docs/v2.x/guide/query-parameters.html#including-relations

jeroenqui avatar Sep 07 '22 10:09 jeroenqui

@jeroenqui i guess that is for GET API.

atapatel avatar Sep 07 '22 14:09 atapatel

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 avatar Sep 09 '22 05:09 alexzarbn

@alexzarbn I agree code will be duplicated :)

atapatel avatar Sep 09 '22 12:09 atapatel

@alexzarbn Any updates on this? Because this is most common requirement in API development.

jiteshgolecha avatar Jun 15 '23 11:06 jiteshgolecha

@alexzarbn any chance to get this feature added?

michaelrimbach avatar Jun 20 '23 07:06 michaelrimbach