Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
The Repository Pattern in Laravel 5
Mar 15, 2016 @ 17:50:05

The TutsPlus.com site has posted a tutorial covering the use of the repository design pattern in Laravel, a popular PHP framework. While the article does introduce some of the basics of the design pattern, a bit more research may be in order if you're not familiar with its base concepts.

The repository pattern was introduced for the first time by Eric Evans in his Domain-Driven Design book. The repository is, in fact, the entry point for the application to access the domain layer.

To put it simply, the repository allows all your code to use objects without having to know how the objects are persisted. The repository contains all the knowledge of persistence, including mapping from tables to objects. This provides a more object-oriented view of the persistence layer and makes the mapping code more encapsulated.

In this article they replace the default storage/persistence method for database records away from the default Eloquent over to Doctrine, a widely used ORM tool. The start with a brief comparison between Eloquent and Doctrine before starting on on a simple "blog" application. They connect Doctrine to Laravel via an "entity manager" and make a basic Doctrine-based model for the Posts and a matching repository/controller implementation. All the code you'll need to implement it is included along with a simple view to take in the post content and display errors if there were any on the save.

tagged: repository designpattern laravel tutorial doctrine eloquent blog

Link: http://code.tutsplus.com/tutorials/the-repository-pattern-in-laravel-5--cms-25464


Trending Topics: