Laravel Tutorials / updated: March 30, 2016

What To Return From Repositories

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?

Source

Laravel News Partners

Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.