R
R
Roman2019-02-17 07:55:04
OOP
Roman, 2019-02-17 07:55:04

Pushing a lot of logic into a model is the Laravel way?

Hello.
A little background: a couple of years ago I undertook to study Yii2 (I quickly stopped this business, because Yii2 is some kind of outrage against common sense), but I remember that there was something about "thick model - thin controller" - and in Laravel , as I see in the examples, all the logic is placed in the controller.
Now I'm doing a project with soft deletion of relations between models and it seems reasonable to me to place the logic of manipulations with relations in the methods of the model.
For example, define a softToggle() method for User to manipulate relations with Role in the User model itself.
How common is this with Laravel?
Or does it not matter at all?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Aksentiev, 2019-02-17
@procode

in the examples , all logic is placed in the controller.

The examples show everything so that it is clear how to use a particular feature.
This is not a style guide for how to write code in general.
in general, the topic is holivar, and there are still two camps for this option or vice versa.
Here everyone decides for himself.

E
Evgeny Romashkan, 2019-02-17
@EvgeniiR

A framework is a tool for solving your problems. You do not have to adapt to the framework, you need to select the tool that suits your goals.
For good, all your business logic should not depend on the framework at all, and in this regard, Yii and Laravel are not doing very well, but Laravel is at least component-based, and you can customize if you understand what you are doing.

R
Roman, 2019-02-17
@procode

and in this regard, Yii and Laravel are not doing very well.

where is good?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question