laravel-json-api / laravel

JSON:API for Laravel applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question | Is it possible to use custom controllers for actions?

jesseyvanofferen opened this issue · comments

I was wondering if it's possible to use a custom / different controller for actions, for example I have the following route defined:

        $server->resource('users', JsonApiController::class)->actions(function ($actions) {
            $actions->get('me');
        });

In this case it's an example and I could easily change the users resource to use a UserController and include all traits, but the question is more about if it would be possible to define a different controller for an action than the resource. Perhaps having something like the UserController for the users resource and having something like a UserActionController for all the actions.

I could not find anything in the documentation about the flexibility in setting different controllers and was wondering if it's possible.

Hi! See you asked this question on Slack as well. As answered there, there's no capability to split resource controller actions across multiple controllers. This matches up with Laravel's resource controllers.