@LPMadness I think one of the important things to take from Jeff's latest video is : Depends.
Basically don't do things because you're supposed to, do them because you need them.
There is no golden rule in any of this unfortunately. Imo.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there,
After watching the last Repository trap cast, I got a little bit confused again.
So far I have a relatively big Laravel project. I am trying to use the repository pattern but I don't think I am doing it the right way. So far I follow this convention:
Model -> eloquent model MorelRepository -> interface extending a Repository contract ModelRepositoryEloquent -> implementation of the ModelRepository interface. (where Moldel is Model name- Customer,Comment,etc)
Each model has a repository and based on the the type of the repository I have extra interfaces and traits that I implement/use (like BelongsToCustomer). On top of that each repository has its own validate method.
Lets assume I have a Comment model that belongs to a Customer model
To save a Comment from my within controller I have to do:
$commentRepository->validate($request->all());
$commentRepository->saveForCustomer($customer, $request->all());
Looked ok to me but recently I found out that its wrong.
$customerRepository->addComment($customer, $comment);
How do I access all comments then? Do I need comment repository too if I want to do that?
Am I right and if so where do I put data and business logic validations? Should I make separate Validation service for each model? Should I place them in the models(isn't that destroying my design pattern)?
@sid405 lol, great post!
I implore you to find the repository bible @LPMadness! Every pattern I have researched has about as many "ways" of doing it as results.
With that said, I don't validate in a repo. I go shortest route. So that's in the controller or a form request. But that's just me. I do advise to be consistent with your decision. For example you decide to validate user registration in your repo and a blog comment in your controller, six months later good luck figuring it all out.
Please or to participate in this conversation.