cloudcreativity / laravel-json-api

JSON API (jsonapi.org) package for Laravel applications.
http://laravel-json-api.readthedocs.io/en/latest/
Apache License 2.0
778 stars 109 forks source link

Handle HasMany relationship with extra field. #636

Closed andrei1820 closed 1 year ago

andrei1820 commented 1 year ago

How can I handle hasmany pivot table, for example 2 foreign key id with a string description?

image

ben221199 commented 1 year ago

Handle the pivot table as a new object, with 2 belongs-to relations.

lindyhopchris commented 1 year ago

Yep that would be the solution. Don't think of it is a pivot, think of it as an intermediary resource. I.e. JSON:API works in resources so you need to represent the pivot table as a resource in your API, with relationships between it and the two related resources on either "side" of the pivot.