How to manage BelongsToMany relationship in Laravel ? #7224
Replies: 1 comment
-
Based on my understanding of the documentation, subresources in API Platform are designed for GET operations so that is not what I need here. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working with API Platform for Laravel and encountering difficulties managing BelongsToMany relationships. While BelongsTo and HasMany relationships work seamlessly by sending IRIs in the request body, BelongsToMany doesn't seem to follow the same pattern.
I'm trying to add users (participants) to a trip when creating (POST) or updating (PATCH) a trip.
Here's the Trip Model:
For BelongsTo (author) and HasMany (stops) relationships, sending IRIs in the request body works as expected during a POST or PATCH operation:
However, when I try to do something similar for the participants (BelongsToMany) relation by including a list of user IRIs:
I receive the following error:
It's not correctly interacting with the BelongsToMany relation to manage entries in the user_trip pivot table.
Thank you in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions