Skip to content

Commit

Permalink
Fix awais-vteams#45 - Return model resource instead of model for api …
Browse files Browse the repository at this point in the history
…controllers.
  • Loading branch information
adwiv committed Dec 17, 2024
1 parent 462ae15 commit 101d9ce
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/stubs/api/Controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,34 @@ class {{modelName}}Controller extends Controller
/**
* Store a newly created resource in storage.
*/
public function store({{modelName}}Request $request): {{modelName}}
public function store({{modelName}}Request $request): {{modelName}}Resource
{
return {{modelName}}::create($request->validated());
${{modelNameLowerCase}} = {{modelName}}::create($request->validated());

return new {{modelName}}Resource(${{modelNameLowerCase}});
}

/**
* Display the specified resource.
*/
public function show({{modelName}} ${{modelNameLowerCase}}): {{modelName}}
public function show({{modelName}} ${{modelNameLowerCase}}): {{modelName}}Resource
{
return ${{modelNameLowerCase}};
return new {{modelName}}Resource(${{modelNameLowerCase}});
}

/**
* Update the specified resource in storage.
*/
public function update({{modelName}}Request $request, {{modelName}} ${{modelNameLowerCase}}): {{modelName}}
public function update({{modelName}}Request $request, {{modelName}} ${{modelNameLowerCase}}): {{modelName}}Resource
{
${{modelNameLowerCase}}->update($request->validated());

return ${{modelNameLowerCase}};
return new {{modelName}}Resource(${{modelNameLowerCase}});
}

/**
* Delete the specified resource.
*/
public function destroy({{modelName}} ${{modelNameLowerCase}}): Response
{
${{modelNameLowerCase}}->delete();
Expand Down

0 comments on commit 101d9ce

Please sign in to comment.