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

Bosnadev.com:
Using Repository Pattern in Laravel 5
Mar 11, 2015 @ 14:51:59

Mirza Pasic has posted a tutorial to the Bosnadev.com site introducing you to the repository design pattern and how to use it in a Laravel 5-based application.

These days there is a lot of buzz about software design patterns, and one of the most frequently asked questions is “How can I use some pattern with some technology“. In the case of Laravel and the Repository pattern, I see often questions like “How I can use repository pattern in Laravel 4″ or nowadays “..in Laravel 5″. Important thing you must remember is that design patterns do not depend on specific technology, framework or programming language.

He starts with a brief overview of the Repository pattern, just to catch everyone up to speed (complete with a diagram for extra effectiveness). He then talks about the role interfaces play in the structure and where in the Laravel directory structure he recommends placing them. He configures the "composer.json" file to autoload them correctly and gets into his actual implementation. He creates a system to work with the push and pull of movie/actor/rental data including the code to make not only the specific repository instances but the generic class they inherit from. Next he creates the "criteria" object type to help with searching the data and makes a few examples ("length over two hours", "rental below three"). Finally he shows how to use this criteria searching in a controller to create custom queries and result sets.

tagged: bosnadev repository designpattern laravel tutorial criteria interface

Link: http://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/


Trending Topics: