Closed MatthiasvanPijkeren closed 7 months ago
Hi. I'd recommend you do the tutorial, because the tutorial covers this topic. https://laraveljsonapi.io/docs/3.0/tutorial/
relationships
member of the CartLine
to associate it to a Cart
./cart-lines
will work...{
"data": {
"type": "cart-lines",
"attributes": {
"foo": "bar"
},
"relationships": {
"cart": {
"data": {
"type": "carts",
"id": "456"
}
}
}
}
}
This should give you enough to go on. The tutorial is there and I'd recommend it as it introduces you to the JSON:API spec (which is what your questions are about) as well as this package.
Also, you might find joining the Slack community a better place to ask questions.
Closing as I think this has been answered.
Hello,
I'm currently working on a project and I'm trying to figure out the best way to create a related model and establish its relationship with an existing model in a single request. Specifically, I want to create a new
CartLine
that belongs to aCart
.Here are the key questions I have:
How do you create a related model (e.g.,
CartLine
) and associate it with an existing model (e.g.,Cart
) in a single request?What is the recommended endpoint to use for this operation? Should it be
/carts/{id}/cart-lines
or/cart-lines
?Could you provide an example of how the request body should be structured for this operation?
Any guidance or examples you can provide would be greatly appreciated. Thank you in advance for your assistance!
Thanks in advance! Matthias