I understand DTOs and they are useful to keep data consistent.
All the examples I see use a DTO to transform data coming into an application from a request, but not data coming out of a database/model.
It got me thinking, should you use a DTO with data coming out of a database, surely the data is consistent as the source is known to you (as it is your database)?
@panthro DTO is good in theory, and it makes sense in some cases, but when we are talking CRUD, there isn't really any need for it.
You have the $request and the eloquent model, those to could be considered as a kind of DTO.
I suggest that you keep it simple and don't make any complex solution for simple crud.
@panthro I hate the repository pattern, it just makes your code look like shit. Just let either the controller, or the model handle it, and use a form request to validate the data from the request.
@Tray2 but the data may not be coming from a request.
Regarding the repository pattern, if you have a complicated select, thats required in many controllers/files, would you repeat this code X times throughout your application? Where would you put it, im in that situation where i need a complex select throughout the application, so have just made a repository to deal with it.