mardi 23 mars 2021

Laravel Controller Pattern, when put all logic?

Turn and move, I'm developing in laravel, and I still don't know what I do when I face this situation,

Usually when you access the controller through any service to search for any resource, such as a list of users, you use it directly in the model, such as

User :: all () and returns, and it's good, the controller doesn't look so dirty, however, when working with reports, the situation seems to get out of control a little

Because you need to access more than one model, do specific searches in the database, calculations too, etc ... Your controller is getting huge and with a lot of responsibilities

I particularly create a helper class and put these functions in it, and then I call the controller, but even so, every time I do this I still do not have the impression that the concept of responsibility has not been defined correctly,

I see people mixing this with the concept of a repository, which also doesn't seem right since the repository serves to create a channel for accessing storage data more like a contract, right,

So, if someone can help me with this question I would be very grateful, where do I put all this logic from the controller?

How do you do it?

#laravel #patterndesign

Aucun commentaire:

Enregistrer un commentaire