M
M
Maxim Zolotoy2019-11-17 16:02:02
Laravel
Maxim Zolotoy, 2019-11-17 16:02:02

How to split models in Laravel?

I am new to Laravel and want to figure out how to organize models. So I created the App/Models folder and the models that are created by Eloquent and work with the database get there.
And where to place models that will have the same name and work with the same entity, but will already contain my methods for working with this entity?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Nikolaev, 2019-11-17
@spacenear

Separating models only makes sense if you, for some reason, want to have ActiveRecord separate from the classic concept of a model in MVC. Usually everyone throws everything in a heap, and nothing needs to be divided. Those parts that are responsible for presenting data in responses need to be moved to resources. Scopes, especially if you repeat them, can be put into traits, and heavy, massive functionality, perhaps, will pull on a separate class or even a service.
I'm somewhat jarred by the fact that in some frameworks AR is a model. However, separating their hemorrhoids is unjustified in 98% of cases.

V
vism, 2019-11-17
@vism

you think right.
The service layer is called.
Services contain business logic, and models contain relays, scopes, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question