Models, repository pattern and Eloquent

Posted 4 years ago by philthathril

Hi. Long time PHP-developer, but fairly new to Laravel and using the repository pattern. I have read plenty of articles, conversations and blogs about repositories. What I just don't seem to understand is when not to use them.

For example, I have a User model with a UserRepository interface and an EloquentUserRepository implementation of that interface.

// model
class User extends Eloquent {
    public function someMethod() {...}
}

// controller
$user = $this->userRepository->findByUsername(...);
$user->someMethod();

What I don't understand is if the User model is really an Eloquent model, but I'm abstracting with an extra layer (my repository), is the above call to someMethod() breaking that pattern? If the repository is essentially hiding the "ORM" portion, should I be calling Eloquent/ORM-related methods on model?

Any tips on how to interact with my models and repositories would be appreciated.

Please sign in or create an account to participate in this conversation.