I
I
Igor Kudryash2017-07-11 20:49:46
Laravel
Igor Kudryash, 2017-07-11 20:49:46

Is there a regular model in laravel, not an Eloquent ORM?

For example, I need a data processing model with validation and other goodies, but it should not be connected to the database. Example from YII2: ActiveRecord and just Model. Is there any analogy in Laravel ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Nesmeyanov, 2017-07-12
@ikudryash

ikudryash :
1) A model (everywhere) is just an application layer of a domain object (ie, some object representing a domain). It does not depend on anything and does not require anything (including inheritance).
2) AR models (well, or any other anemic models) should never, under any circumstances, contain business process validation. This is the responsibility of DbC invariants. If you don't like it, DTO is considered common practice. In the case of Laravel, everything was simplified for you and washed down on a silver platter with FormRequests, which are automatically validated when resolving from the container (that is, when injecting).
3) Validation of business logic should always be one level higher, because the rules for creating entities are tied to the immediate scope (including user rights and other things, that is, it depends on the task) and can be different in different places.
4) To use external services, Laravel has a container that implements autowiring and double dispatch, unlike Yii, where there is no such thing and the frame is stuffed with hidden dependencies.

J
JhaoDa, 2017-07-11
@JhaoDa

This is a regular class. Does PHP have classes? Again, there are FormRequests for processing specific forms, for validating everything else there is just a validator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question