Answer the question
In order to leave comments, you need to log in
Logic in Laravel is written in controllers?
According to the concept of MVC, the logic is written in the models, isn't it?
Look in Laravel for recording and fetching and everything else in controllers. This is the case?
Answer the question
In order to leave comments, you need to log in
MVC is the division of the entire application logic into 3 components. There is logic in each of these components.
Most likely the question is where to process certain data before giving it to the view, where to put the logic. It is generally accepted, and everywhere they write that the controller must be thin. So, to make it right, we shove all the logic into the model. But here you need to understand that the Model is not only the Active Record class, or ORM is also classes of various services, repositories, for example, form objects, validators - these are the same models, and they also have logic.
The fact that all code can be written only in controllers, models and views and nowhere else, because we write MVC (what else happens?) - this is a misconception that needs to be eliminated as quickly as possible. Because code by and large cannot be written either in models, or in controllers, or in views - it does not belong there. The code must be written in php classes , which are then connected to controllers, cli command processing files, commands executed in a queue, daemon files, etc. The code must withstand the procedure of changing the php framework simply by copying all the files and edits of repository classes and other interface classes with a specific framework. If your code is tightly fused to the current framework, this is a sign that something has gone wrong.
Create your own folders inside the app folder, lay out classes there and connect them in the controller constructor. Read what types of classes are in terms of application architecture, read about the SOLID principle. Read about Domain Driven Design, google talks, for example https://www.youtube.com/watch?v=rjtbCyacJas .
Learning is an ongoing process, don't stop.
The controller is a layer between the business logic and the user, the controller receives data from users and gives the necessary data from the model
Look in Laravel for recording and fetching and everything else in controllers.
in off docks even validation in the controller
Written an hour ago
According to the logic of things, it should be like this:
The model is responsible only for the validity of the data.
The controller is responsible for the business logic.
The presentation is clear for what it is responsible for.
Very strange specialists keep the business logic in the models.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question