PHPackages                             lukaskorl/repository - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. lukaskorl/repository

ActiveLibrary[Database &amp; ORM](/categories/database)

lukaskorl/repository
====================

Powerful implementation of the repository pattern for Laravel 4 with a simple API

v0.8.4(11y ago)79311MITPHPPHP &gt;=5.4.0

Since Jun 4Pushed 11y ago3 watchersCompare

[ Source](https://github.com/lukaskorl/repository)[ Packagist](https://packagist.org/packages/lukaskorl/repository)[ RSS](/packages/lukaskorl-repository/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (4)Versions (15)Used By (1)

Repositories for Laravel 4
==========================

[](#repositories-for-laravel-4)

*Repository* is a powerful implementation of the repository pattern for Laravel 4 with a simple API.

To install *Repository* in your Laravel project simple execute `composer require lukaskorl/repository`.

**Word of caution**: *Repository* is currently under heavy development. I will release a stable version 1.0.0 soon. Until then the interface may change. I do not recommend to use *Repository* as a `dev-*` dependency in production code.

Introduction
------------

[](#introduction)

A repository acts as a mediator between the domain logic and the data mapping layer. This means the repository sits between your code handling your business cases and the code accessing databases, APIs, filesystem, ...

You may benefit from using a repository in many ways:

- Complicated queries on your data may be encapsulated in the repository and accessed by your business logic anywhere with a simple method call.
- The complete data representation may be switched from a database to an API without touching a single line in your business logic.
- A repository may decouple your database columns from the rest of your code. By transforming attribute names and applying the correct data type to an attribute.

There are other benefits which I won't discuss here. If you want to read more about the repository pattern continue reading on [Martin Fowler's website](http://martinfowler.com/eaaCatalog/repository.html).

Basic Usage
-----------

[](#basic-usage)

*Repository* provides you with a set of tools to conviniently implement the repository pattern. By default *Repository* only implements CRUD-style querying. But feel free to enhance your repositores with other methods and complex querying.

A simple use case scenario include three tools provided by *Repository*:

- **(optinally)** provide an implementation of the abstract class `Lukaskorl\Repository\Transformable\Transformer`. This class will handle renaming and typing of attributes.
- Implementation of the `Lukaskorl\Repository\AbstractRepository` (i.e. `Lukaskorl\Repository\EloquentRepository` if you want to use Eloquent as an ORM). Feel free to implement your own repository strategy i.e. to access an API or other databases. I will add more implementations in the future.
- `Lukaskorl\Repository\RepositoryController`

### Transformers

[](#transformers)

The usage of a transformer is optionally. If you do not want to rename attributes or to ensure typing you can use *Repository* without transformers. Typically your transformer will look like this:

```
