W
W
web-quest32017-08-27 20:29:08
Laravel
web-quest3, 2017-08-27 20:29:08

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

7 answer(s)
N
Nikolai Egorov, 2017-08-27
@nickicool

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.

A
ajaxtelamonid, 2017-08-28
@ajaxtelamonid

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.

A
Anton, 2017-08-27
Reytarovsky @Antonchik

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

P
pantagruel964, 2017-08-27
@pantagruel964

Look in Laravel for recording and fetching and everything else in controllers.

Where you write, there it will be. The framework does not restrict or impose anything on you.
Understand what a model is. The impression that for you the model is the Model.php file

A
Alexander Aksentiev, 2017-08-27
@Sanasol

in off docks even validation in the controller
Written an hour ago

offdocs are docks in order to find out how this or that function works.
There is no task to teach you how to use MVC, the task of the docks is to give the simplest code so that you understand how something works.
They do not describe what and where to shove.
controllers or models are a holistic question.
It is more convenient in models if the project is complex.
In controllers it will do if you don’t give a shit where and what, as long as it works.
In this case, it will not be necessary to reuse the functionality in another part of the project.
Otherwise, questions come up: how to call a method of controller B from controller B.
The answer is always the same: no way, controllers are not some kind of global classes with functions, they have a specific one functionality. And you can’t call one from the other, it’s pornography.

M
Maxim Fedorov, 2017-08-28
@Maksclub

TTUK -- stupid fat ugly controller

Q
Q2W, 2017-08-28
@Q2W

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 question

Ask a Question

731 491 924 answers to any question