flugg / laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.
MIT License
861 stars 86 forks source link

How do I use getResourceKey() on Relationship? #177

Open wukongrita opened 3 years ago

wukongrita commented 3 years ago

Hi @flugg ,

I have setup my models with getResourcKey() for both models:

NelitiVolume.php

. . .
    public function getResourceKey(): string {
        return 'neliti-volumes';
    }
. . .

NelitiPublication.php

. . .
    public function getResourceKey(): string {
        return 'neliti-publications';
    }
. . .

When I try to get the result from the url using /neliti-volumes?include=neliti-publication, I get the type is using camel-case; not using the kebab-case that I already defined in the models:

{
  "data": [
    {
      "type": "neliti-volumes",
      "id": "088f4670-8993-4ffc-86e4-58036442cebe",
      "attributes": {
        "volume": "BB",
        "number": "3",
      },
      "relationships": {
        "neliti-publication": { // this one is from the url that mapped with the transformers
          "data": {
            "type": "nelitiPublication", // this one should be neliti-publications that get from getResourceKey()
            "id": "39676c75-6e03-11ea-9660-ed7fb61131c5"
          }
        }
      }
    },
    . . .
  ]
}

Btw, I am using JSON API Serializer from PHP League...

Did I miss something?