fractal icon indicating copy to clipboard operation
fractal copied to clipboard

JsonApiSerializer and $resourceKey

Open b-hobbs opened this issue 10 years ago • 5 comments

Hello, sorry if this has already been answered but I couldn't find anything related.

For the JSON-API Serializer you need to pass in a $resourceKey.

// Important, notice the Resource Key in the third parameter:
$resource = new Item($book, new JsonApiBookTransformer(), 'books');

But wouldn't a given transformer typically have the same type for it's response? A book would always be of type books. Wouldn't it be better to declare a default type in the transformer?

b-hobbs avatar Dec 04 '15 21:12 b-hobbs

I ended up writing something to handle exactly this. Essentially, I store a $resourceKey on the Transformer and each transformer defaults to using that. However, the user can still pass a string in via the default implementation to override the Transformer's key.

dtirer avatar Feb 23 '16 21:02 dtirer

@dtirer If you are willing, would you make a pull request with that functionality? If not then I'll do it over the weekend.

willishq avatar Mar 03 '16 21:03 willishq

@willishq sure, I'd be interested. I should be able to do it in the next few days

dtirer avatar Mar 05 '16 15:03 dtirer

Any news on this?

lukasoppermann avatar Apr 02 '16 16:04 lukasoppermann

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 07:04 stale[bot]