cloudcreativity/laravel-json-api

Handle HasMany relationship with extra field.

andrei1820 opened this issue · 2 comments

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

image

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

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.