Answer the question
In order to leave comments, you need to log in
Who can understand if my logic is correct in understanding patterns in laravel?
So here's my logic
1) Client
sent a request to the server
2) Middleware
processes it and passes it to Controller
3) Controller
receives a request from the client
4) Controller
fetches data from the database using Repository
or populates DTO
and passes it to Service
where it processes DTO
and writes to the database. Or execute other business logic in Service
and then return data in Controller
5) Controller
send response to client
I have 2 questions
First: Is my logic close to good programming patterns or can you recommend something to change?
Second:If I want to set up my app on startup (like hook events, initialize cart, etc.), where can I do that? Maybe in Middleware
? And where can I write this logic? In some Service
too?
Answer the question
In order to leave comments, you need to log in
2) Middleware does not process anything, this is done by the web server, the entry point file public/index.php and HttpKernel.
4) Why "or"? DTO is needed in order to have strict typing of fields and simplicity of the refactor. There are parameters from the front - be kind DTO, the repository has nothing to do with this.
What you have in your controller - a service, a repository, or something else - is not particularly important, these are the details. The main thing is that it would be easy to test.
Questions:
1) Yes, normal. Nothing distinguishes it from the docks, because in principle it does not dictate what to do next with the controller, and there are different practices. DTO is a very, very good thing, and the rest is very subjective.
2) in service providers. boot() for everything, register() for registering things into the container.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question