Where to make the logic of the sample?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
15 views
Tell me where is better to make various checks for the sample data? Let's say you have a website with ads and you need to get the ads that are placed by the user, and which he used.. One of the options, what the most popular is the 2 lines in the controller:

$selling = Ads::where('owner_id', 23); $purchases = Ads::where('buyer_id', 23);


But I understand that this is a bad solution for less complex projects, it is necessary somewhere this logic to make.. model to bear it, do not want to Service for do also think like that is wrong.. Maybe I will shift the doctrine to dig? Or it need the repository to do? In General, prompt how better to do it..
by | 15 views

1 Answer

0 like 0 dislike
The whole database should be in the repositories.
The repository works with entity, so that, in the case of using an active record ORM, of the ar model would need to create an entity and return it from the repository. Do not give the DB connection to "walk" on the project. This is a common popo Entity which has no any logic, but only a set of fields, getters, and of the methods for status updates.

For example:
class UserRepository implements EloquentUserRepository { public function findBySomething(string $something): ?UserEntity { $user = User::where('something', $something)->first(); if ($user !== null) { return new UserEntity($user->id, $user->something); } return null; } }


Maybe I will shift the doctrine to dig?

The right decision. It's better to abandon eloquent and hire doctrine, if the project requires a serious ORM.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked May 21, 2019 by enigma2030
0 like 0 dislike
1 answer
asked Apr 5, 2019 by Alex1237
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users