laravel-json-api / laravel

JSON:API for Laravel applications
MIT License
551 stars 42 forks source link

Custom controller actions and attributes structure #231

Open invaders-xx opened 1 year ago

invaders-xx commented 1 year ago

I have a Schema and a Controller which implements the standards. I want to add several actions to that controllers. Each post action accepts a different data structure. How can I handle that as the data structure is related to Schema fields definition. Or maybe I missed smth. I am using cloudcreativity/laravel-json-api in previous projects . But as mentioned, for new projects, this package should be used but I feel confused/lost with this new package

lindyhopchris commented 1 year ago

By "actions", do you mean custom actions? If you're using different data structures, for custom actions, there's not much I can do to support it - as the point of the package is to handle the JSON:API spec. Which means it can't handle custom things that deviate from the spec.

Unless I'm missing something about your question? You might need to provide an actual example - if you're doing something that is covered by the spec but you can't find a way to make it work?

invaders-xx commented 1 year ago

I just need to to have a custom action within a controller using a custom request with rules. In previous version I was using Validators. But now, if I define rules for this specific action I need to define the fields within the schema, which could be different with the standard schema of the resource associated with this schema

lindyhopchris commented 1 year ago

Yeah I'm a bit lost, sorry. The schema is meant to define the resource representation in the JSON:API compliant server. I'm not sure why the schema would be changing? E.g. if you have a posts resource, then the schema should represent that resource... the resource shouldn't change structure in different scenarios as that would be unpredictable to the client.