-
Notifications
You must be signed in to change notification settings - Fork 107
Custom resource routes #63
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! Glad you like the package. And thanks for raising this, as this is something I'd like to get settled for v1.0 so your ideas would be useful. At the moment you need to use the traditional Laravel router methods, e.g.: JsonApi::api('default', ['as' => 'api.'], function ($api, $router) {
$api->resource('posts');
$router->get('posts/my-action', 'PostsController@myAction');
$api->resource('comments');
}); This however won't have the authorization or validation middleware that is applied using Let me know how you get on. I'm not totally sure how to integrate custom actions as technically they are outside the spec, so it's a bit difficult for me to reason about how to handle them within the package. |
Actually, looking at the code I'm not 100% sure this will work: building the JSON API request object might get in trouble as it uses the request interpreter for that. If it doesn't work, you'll have to define it outside the I might have to look into this a bit more. |
Thanks for the fast reply! In the meantime I have found a way to replace the need for a custom route with a simple filter inside the adapter, so please don't put too much effort into this issue :-) Adding the custom route inside the |
yeah, that's along the lines of what I was thinking too. I'll leave this issue open so that it doesn't fall off the radar! |
@flofloflo Could you elaborate on how exactly you overcame this issue using a filter? I'm stuck in the exact place you were... |
I'm sorry, I don't exactly recall what my problem was back in May. But I remember that after some thinking I realized that I didn't need a separate controller method but rather a filter for my database query. Filtering can easily be done through the adapter: -> See the example from the demo If you need a plain JSON API response without the magic of this package, you could also try Fractal with the JsonApiSerializer and build the response manually. (That's what I did in an other case) |
@tooshay hey! if you let me know what you're stuck on I'd be happy to help |
Closing this in favour of #196 A solution to custom routes will be available in |
Hello, first of all thanks for sharing this great project with the public!
I'm trying to set up a custom resource route but can't find a way to do it properly. The routing documentation only shows the possibility to include or exclude controller actions of the predefined pool (index, create, read, etc.).
Is it possible to create a custom route which points to a custom controller action inside of the
JsonApi::api( ... )
block? Or is this the wrong place for custom actions and the route should be defined "by hand" as classicRoute::get( ... )
?The text was updated successfully, but these errors were encountered: