Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JamieHoward's avatar

Resource controller structure within API

I want to build a web application in the traditional MVC sense of having controllers for each resource that interact with a model layer. However, I'm trying to understand how to structure the API that would go along with the browser-accessed application. I realize the API would interact with the same model layer that the main web app would, but do I create another set of controllers for each of the resources, or do I just create methods specifically for the API routes within the existing controllers?

Just trying to understand what this looks like from a Laravel structure perspective. Thanks in advance for any feedback!

0 likes
1 reply
davorminchorov's avatar
Level 53

I think it's better if you create a different set of controllers under a new namespace (Api) and put them in a version folder (v1 for example) so you can keep the code for every version of the API separate.

Same goes for routes, keep them in different files.

You'll end up having 2 data representations of the same application under one roof which will share a few classes.

That's how I would do it.

1 like

Please or to participate in this conversation.