I feel that Taylor and I may have led some of you astray in the Laravel community. After a few posts about dependency injection and the Repository pattern, it seems as if it is now the de facto setting for all Laravel 4 apps to use Repositories.

While Repositories are great, there is a bit of a question of "will I ever need this layer of abstraction?" Sometimes, the answer is a solid no. Other times you are rapidly prototyping and don't want to muck about throwing in extra abstraction when you know a long period of refactoring is to come. The fact is Repositories and contracts are great when you expect change while maintaining a certain API for an area of code.

Yesterday, I released a the initial Laravel 4 implementation of OrderMVC. Soon after, I had questions raised on why the project didn't use Repositories. The fact is that the project wouldn't have benefited from Repositories that much. In the OrderMVC guidelines it states that projects should use the native ORM as much as possible. On top of this, the project is a show of the framework, not architecture patterns or the way that PHP works. Greater levels of abstraction would have distracted users from seeing how Laravel works and would have required more time digging around.

In your own applications consider your audience. Will you possibly use Caching to quick store results (or some other form of interaction with your data before/after interacting with the ORM)? If you are on a short-term project that isn't going to be following TDD, go for broke and don't use Repositories! After a while, you start over architecting your applications and before you know it you're creating 30 interfaces during a hackathon project. It gets to be a burden.

However, there are clear times when you want to use Repositories. When creating packages, I'd recommend using Repositories so that you have a clear contract for developers to follow if they want to create other implementations. If you have a long term project that you plan on optimizing queries (result caching). If you plan on test driving the application.

So, think if you really should use that Repository next time. Maybe you need to grab a screwdriver.