Skip to content
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

Api controller does not use ModelResource for all methods #45

Closed
adwiv opened this issue Dec 16, 2024 · 1 comment
Closed

Api controller does not use ModelResource for all methods #45

adwiv opened this issue Dec 16, 2024 · 1 comment

Comments

@adwiv
Copy link
Contributor

adwiv commented Dec 16, 2024

In the generated API controller, the generated Model Resource is used only for index method.

All other methods simply return the model object.

We should ideally use ModelResource everywhere in the API controller.

In the generated Api\UserController.php

public function show(User $user): User
{
    return $user;
}

should be

public function show(User $user): User
{
    return new UserResource($user);
}

Similar change for other methods - store and update.

@awais-vteams
Copy link
Owner

I would be happy if you pushed the PR. I'll be checking in the next release.

adwiv added a commit to adwiv/laravel-crud-generator that referenced this issue Dec 17, 2024
@adwiv adwiv mentioned this issue Dec 17, 2024
adwiv added a commit to adwiv/laravel-crud-generator that referenced this issue Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants