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

alessandrobelli's avatar

Best practices for CRUD model

Hi! I'm trying to stick to a CRUD model for my project, but sometimes is rather hard to do it. I have 2 questions about it:

  • where do I put the API methods? In an API controller or something like UserApiController.php? Or one big ApiController?
  • I can reduce every controller to a CRUD model easily, but since my projects are rather complicated I need several other functions. For example, I want display the result from a "survey" (case) and I need all the available inputs that were set from in the questionnaire (Project), for this I have a ProjectCaseController@getInputValues which doesn't really stick to the CRUD model. Where should I put a function like that?
  • Where do I put the "Admin" functions that belongs to different models but are not CRUD? For example, if I want to delete all the project that belongs to a user, where do I put the method "deleteAllProjectByUser" ?
0 likes
4 replies
alessandrobelli's avatar

I actually started months ago with that video and I remember that was really useful to create controllers to create methods in between models: ProjectCasesController - CasesEntriesController and so on. I actually don't remember to have seen something for "functions within those controllers that don't belong to any model", but I will definitely watch it again :)

bugsysha's avatar

functions within those controllers that don't belong to any model

Please elaborate a bit more cause I'm not sure what you are referring to.

bugsysha's avatar

If I understand correctly, create ProjectCaseInputValueController and within index method return all your input values.

Then deleteAllProjectByUser becomes UserProjectController with destroy method.

Or you can maybe even go with UserProjectBulkController with destory method. Not a good solution but if that is what you are happy with then fine by me.

1 like

Please or to participate in this conversation.