jeudi 9 janvier 2020

laravel where to put each kind of logic

I am having some suggestions of how code should be written in laravel and just curious what you think about them and if you can add more of your ways or at least let me know if i am thinking wrong.

So, let's say we are building a huge app. So we have business logic, queries and lots of things.

WAY 1) Controller->Service->Repository->Model(Controller calls Service directly, Service has some business logic and then calls repository, repository has eloquent models and big queries. note: the actual queries stay in repositories. models only have scopes, accessors, mutators and this kind of staff to keep it small.

WAY 2) Controller->Repository->Model ( this is kind of not great, because the only place that we could write business logic seems to be Controller. Repository is just for query staff. and this leads to fat controllers. I guess the WAY 1) is much better.

I don't have repository interfaces since let's say we don't plan on switching implementations and stick to only eloquent.

What do you think? agree ? any other ideas?

Aucun commentaire:

Enregistrer un commentaire