Skip to content

Since Laravel support pivot columns in m-to-m relationships, is it possible to create an extension to support it here ? #114

Open
@Mina-R-Meshriky

Description

@Mina-R-Meshriky

this is for only many-to-many relationships, since this kind of relations constitutes an additional table in the database, and sometimes this table can have some additional pivot columns.

According to jsonapi we can't include an "attributes" key in a relationship. However, we can add a "meta" key.
so can we add pivot columns as the following example ?

{
  "data": {
    "type": "posts",
    "attributes": {
      "content": "...",
      "slug": "hello-world",
      "title": "Hello World"
    },
    "relationships": {
      "tags": {
        "data": [
          {
            "type": "tags",
            "id": "1",
            "meta": {
                "pivot": {
                     "published": true
                 }
            }
          }
        ]
      }
    }
  }
}

for now I am accomplishing this by the above request body example, but with also using the hooks in the controller to override the functionality to get the pivot and adding it to the flow.

in the documentation it is recommended to create a resource for that pivot table, but it just seems to be an overkill for this task, also it will introduce more routes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions