Download the PHP package mnshankar/repository without Composer
On this page you can find all versions of the php package mnshankar/repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mnshankar/repository
More information about mnshankar/repository
Files in mnshankar/repository
Package repository
Short Description Reusable repository interface - Forked from Caffeinated/repository, modified to work with Laravel 5.0/php 5.4
License MIT
Informations about the package repository
Caffeinated Repository
This is a fork of the Caffeinated Repository package for LARAVEL 5.0 (using PHP 5.4)
Getting Started
Introduction
The Caffeinated Repository package implements a standard boilerplate repository interface. This covers the standard Eloquent methods in a non-static, non-facade driven way right out of the box. Fear not though Batman! The Caffeinated Repository package does not limit you in any way when it comes to customizing (e.g overriding) the provided interface or adding your own methods.
If you want database result caching to work, please note that you need a caching solution that supports "tags" (ex. Redis/Memcached). This package automatically caches data retrieved through the repository (for 60 mins). It also handles cache busting (based on tags) for data that is updated via the repository. In fact, it is for this feature that Caffeinated/repository requires the use of a caching store with Tags feature - It makes removing chunks of data from the cache easy.
Installing Caffeinated Repository
It is recommended that you install the package using Composer.
IMPORTANT: Also add the service provider to your app/config.php file - This sets up eventing so updates through your repository invalidate the cache, thus forcing a requery.
This package is compliant with PSR-1, PSR-2, and PSR-4. If you find any compliance oversights, please send a patch via pull request.
Using Repositories
Create a Model
Create your model like you normally would. We'll be wrapping our repository around our model to access and query the database for the information we need.
Create a Repository
Create a new Repository class - usually these classes are simply stored within a Repositories
directory. There are a few requirements for each repository instance:
- Repository classes must extend the EloquentRepository class.
- Repository classes must specify a public property pointing to the model.
- Repository classes must specify an array of cache tags. These tags are used by the package to handle automatic cache busting when relevent values change within the database.
Injecting a Repository
Once you've built and configured your repository instance, you may inject the class within your controller classes where needed:
The interface defined in src/Contracts/Repository.php details the methods implemented by the EloquentRepository class. These are listed below for your convenience:
Event listeners in "Listeners\RepositoryEventListener" take care of invalidating cache on create, update and delete. Note that you may manually flush the cache associated with any of your repositories using
While these methods should take care of 80% of your needs, you may define additional methods as required by your app in your repository class. Refer to the EloquentRepository class for implementation details.