What To Return From Repositories
Published on by Eric L. Barnes
Good discussion around repositories and also some good comments.
Repositories are swell. It’s a great idea to have a central place to retrieve entities(models) from. They’re even better if you’re interfacing them and have different implementations, like an EloquentPersonRepository. It’s awesome to hide your ORM behind an interface. Your calling code likely doesn’t need to know the ORM exists…but the repositories will still return
models to the client code. Isn’t the client code suppose to be unaware of the ORM? It doesn’t make sense for your client code to do something like, $person->siblings()->attach($brother) when attach() is an Eloquent method. What do you do then? have your repositories cast everything to arrays? convert them to instances of stdClass?
Eric is the creator of Laravel News and has been covering Laravel since 2012.