-
Notifications
You must be signed in to change notification settings - Fork 106
Question: How to add custom action to resource constroller? #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi! You can register any route you want using the normal Laravel route registrations. Is your action planning on receiving JSON API payloads and/or returning JSON API payloads? |
@lindyhopchris action expects ID as input (post method) and should return shared resource as JSON-API response. |
So just write the share action method in the way you would a normal Laravel route. Don't inject any of the JSON API dependencies such as To return a JSON API response, you can use the This should work but let me know if it doesn't and I can help you work out the bugs. I should probably add this scenario to the tests and docs so that we know it does work as it definitely is something you should be able to do! |
Thanks for detailed answer! I'll try it soon. |
It works! Thank you! |
@tekord is this how you organized the routes?
|
@edeis53 yes. |
@lindyhopchris how to get includes to work on the custom endpoint? I've loaded the $record just the same as the read() action. Made sure $store->readRecord() includes an EncodingParameters object with the appropriate includes. The record returned has the included records, but the includes are not being outputted by the reply() helper, just the record. I compared the $record being passed to Is there an issue with the validator not working here and excluding the include data? |
It's probable that the responses factory (that you access via This isn't really tested at the moment which is why you've probably stumbled across this! I think as there's a lot of people asking about custom endpoints I need to get this better supported and documented for |
in the interm, do you have any suggestions on how I could inject the encoding parameters into the responses factory? |
This allows them to be parsed and used in custom routes. See #196
@edeis53 I've just pushed a change to the This means when you now use A quick warning on this - if you haven't validated the query parameters, then the client will get a The |
Hi! Thanks for package. I found nothing in documentation about my question. How I can add custom action to resource controller? For instance: I have PostController, this controller extends JsonApiController, inherits index, create, update, etc. And I want to add 'share' action.
The text was updated successfully, but these errors were encountered: