M
M
Muhammad2016-07-05 09:42:50
Software design
Muhammad, 2016-07-05 09:42:50

Smart architecture in Laravel?

There is, for example, a repository (like this: vk.cc/5lHdAR, https://laravel.ru/posts/41). While simple queries are needed (get all records, find a record by one field, etc.) everything is ok, but as soon as the queries become at least a little more complicated (get a record from a database with links, or find a record by several fields), the code turns into a mess and the repo class gets very fat. I saw somewhere a screen where queries are placed in a separate class, I read about the Query Object Pattern (I don’t know if it’s this). In general, it would be nice if someone shared their ideas about this, and even better code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Plisko, 2016-07-05
@muhammad_97

Nonsense, both examples return AR, there is no point in such repositories. This suffered 100,500 years ago, when there were no 100,500 sensible db and it was invented not for dying php, but for systems where objects are stored in memory for a long time and only sometimes persist. I thought about 10 years ago everyone suffered this garbage, but no, the fashion for ddd returned.
Repositories should remain simple, if additional checks, joins, conditions, sortings are needed, then create criteria and specifications https://en.wikipedia.org/wiki/Criteria_Pattern https://en.wikipedia.org/wiki/Specification_pattern

M
Muhammad, 2016-07-07
@muhammad_97

stackoverflow.com/questions/16176990/proper-repositories...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question