PHPackages                             reynholm/laravel-repositories - 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. reynholm/laravel-repositories

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

reynholm/laravel-repositories
=============================

Provides an easy way to create your laravel repositories

0.17.3(11y ago)4421[5 issues](https://github.com/reynholm-industries/laravel-repositories/issues)MITPHPPHP &gt;=5.4.0

Since Sep 1Pushed 11y ago3 watchersCompare

[ Source](https://github.com/reynholm-industries/laravel-repositories)[ Packagist](https://packagist.org/packages/reynholm/laravel-repositories)[ RSS](/packages/reynholm-laravel-repositories/feed)WikiDiscussions develop Synced 3w ago

READMEChangelogDependencies (10)Versions (14)Used By (0)

Laravel Repositories
====================

[](#laravel-repositories)

[![Latest Stable Version](https://camo.githubusercontent.com/1ef4c0f34f300c3129daea659e4cbc9269c7f9cae2eef1c5a48f52fd350056e8/68747470733a2f2f706f7365722e707567782e6f72672f7265796e686f6c6d2f6c61726176656c2d7265706f7369746f726965732f762f737461626c652e737667)](https://packagist.org/packages/reynholm/laravel-repositories)[![Build Status](https://camo.githubusercontent.com/01480f57c0c3a1226ad7aa88c02f4c495bdc8c68a4d906d7138a8bbed90e15c8/68747470733a2f2f7472617669732d63692e6f72672f7265796e686f6c6d2d696e64757374726965732f6c61726176656c2d7265706f7369746f726965732e737667)](https://travis-ci.org/reynholm-industries/laravel-repositories)[![Coverage Status](https://camo.githubusercontent.com/48e8415c3f6b0cd7f9887cf75cc1d69ef5a56e9334776905322ee1badaf1abee/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7265796e686f6c6d2d696e64757374726965732f6c61726176656c2d7265706f7369746f726965732f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/reynholm-industries/laravel-repositories?branch=master)[![Total Downloads](https://camo.githubusercontent.com/7b089f0f2fd202c4c50146cfe61a8408c0394fb91ca9203deb1a2f7bb66ee4f9/68747470733a2f2f706f7365722e707567782e6f72672f7265796e686f6c6d2f6c61726176656c2d7265706f7369746f726965732f646f776e6c6f6164732e737667)](https://packagist.org/packages/reynholm/laravel-repositories)[![License](https://camo.githubusercontent.com/f26dae4427d38654b7ec0e402fe4ad1be21945676c3dc02d5d3d708094cda50e/68747470733a2f2f706f7365722e707567782e6f72672f7265796e686f6c6d2f6c61726176656c2d7265706f7369746f726965732f6c6963656e73652e737667)](https://packagist.org/packages/reynholm/laravel-repositories)

Repository pattern for Laravel

Installation and Configuration
==============================

[](#installation-and-configuration)

Add this to your composer.json

```
{
    "require": {
        "reynholm/laravel-repositories": "0.16.*"
    }
}
```

Abandoned!
==========

[](#abandoned)

This package is abandoned as you can see on packagist. I moved to python and I have no time for keeping this repo up to date with Laravel. Feel free to fork it and maintaining it yourself.

Notice
------

[](#notice)

I think that you can use it even that is on an early stage, but I may make some breaking changes so if you don't want any surprises just don't put "dev-master" or an asterisk as your composer version. Be smart!

If you put your version like on the above example you will not get any breaking changes.

Usage
=====

[](#usage)

Simply extend the abstract class Reynholm\\LaravelRepositories\\Repository\\LaravelRepository

Example
-------

[](#example)

```
use Reynholm\LaravelRepositories\Repository\LaravelRepository;

class UserArrayRepository extends LaravelRepository
{
    //defaults to laravel's default connection
	//protected $connection = 'mysql';

	//If no tableName is specified it will be guessed based on a snake_case version of the CamelCase
	//class name without the repository part and pluralized.
	//Examples: UserRepository => users, CustomerHistoryLog => customer_history_logs, etc...
    //protected $tableName  = 'users';
}
```

Fetch Mode
----------

[](#fetch-mode)

You can also choose the fetcher that you like the most or create your own. You can select the one that you prefer from the LaravelRepositoryInterface constants. Example:

```
    class YourRepository extends LaravelRepository {
        protected $fetchMode = LaravelRepositoryInterface::FETCH_AS_LARAVEL_COLLECTION_OBJECTS;
    }
```

So the repository will return a Illuminate\\Support\\Collection with objects.

Currently implemented methods:

```
     /**
      * @param int $id
      * @param array $columns Restrict columns that you want to retrieve
      * @return array
      */
     public function find($id, array $columns = array());

     /**
      * @param int $id
      * @param array $columns Restrict columns that you want to retrieve
      * @return array
      * @throws EntityNotFoundException
      */
     public function findOrFail($id, array $columns = array());

     /**
      * @param array $criteria
      * Ex.:
      * array(
      *     array('name', '=', 'carlos'),
      *     array('age',  '>', 20),
      * )
      * @param array $columns Restrict columns that you want to retrieve
      * @return array
      */
     public function findOne(array $criteria, array $columns = array());

     /**
      * @param array $criteria
      * Ex.:
      * array(
      *     array('name', '=', 'carlos'),
      *     array('age',  '>', 20),
      * )
      * @param array $columns Restrict columns that you want to retrieve
      * @param integer $limit
      * @param array $orderBy
      * Ex.:
      * array(
      *     array('name', 'asc'),
      *     array('age', 'desc'),
      * )
      * @return array
      */
     public function findMany(array $criteria, array $columns = array(), $limit = 0, array $orderBy = array());

     /**
      * @param array $columns Restrict columns that you want to retrieve
      * @param int $limit
      * @param array $orderBy
      * Ex.: ['name' => 'asc', 'age' => 'desc']
      * @return array
      */
     public function findAll(array $columns = array(), $limit = 0, array $orderBy = array());

     /**
      * Get an array with the values of a given column.
      *
      * @param  string  $column
      * @param  string  $key
      * @return array
      */
     public function lists($column, $key = null);

     /**
      * @param array $data The resource that you want to create
      * @param bool $force If force is false and data is not valid error will be throwed
      * @return boolean
      * @throws DataNotValidException
      */
     public function create(array $data, $force = false);

     /**
      * @param array $data The resources that you want to create
      * @param bool $force If force is false and data is not valid error will be throwed
      * @return boolean
      * @throws DataNotValidException
      */
     public function createMany(array $data, $force = false);

     /**
      * @param array $criteria
      * Ex.:
      * array(
      *     array('name', '=', 'carlos'),
      *     array('age',  '>', 20),
      * )
      * @return int
      */
     public function count(array $criteria = array());

    /**
     * Update a resource by its id
     * @param int $id
     * @param array $data
     * @return boolean
     */
    public function update($id, array $data);

    /**
     * Update one or more resources
     * @param array $criteria
     * @param array $data
     * @return int Number of affected rows
     */
    public function updateMany(array $criteria, array $data);

     /**
      * Validates the input array and stores all the errors,
      * them, you can get them with the getErrors() method
      * @param array $data
      * @return boolean
      */
     public function validate(array $data);

     /**
      * Validates the input array and stores all the errors,
      * them, you can get them with the getErrors() method
      * Same af validate but specify the rules, instead of using the repository rules
      * @param array $data
      * @param array $rules
      * @return boolean
      */
     public function validateWithCustomRules(array $data, array $rules);

     /**
      * Validates the input array or throws exception
      * It also stores all the errors. Then you can retrieve them with the
      * getValidationErrors() method
      * @param array $data
      * @throws DataNotValidException
      * @return void
      */
     public function validateOrFail(array $data);

     /**
      * Validates the input array or throws exception
      * It also stores all the errors. Then you can retrieve them with the
      * getValidationErrors() method
      * @param array $data
      * @param array $rules
      * @throws DataNotValidException
      * @return void
      */
     public function validateWithCustomRulesOrFail(array $data, array $rules);

     /**
      * Validates a multidimensional
      * It also stores all the errors. Then you can retrieve them with the
      * getValidationErrors() method
      * @param array $data
      * @return boolean
      */
     public function validateMany(array $data);

     /**
      * Validates a multidimensional
      * It also stores all the errors. Then you can retrieve them with the
      * getValidationErrors() method
      * Same af validate but specify the rules, instead of using the repository rules
      * @param array $data
      * @param array $rules
      * @return boolean
      */
     public function validateManyWithCustomRules(array $data, array $rules);

     /**
      * Validates a multidimensional or throws exception
      * It also stores all the errors. Then you can retrieve them with the
      * getValidationErrors() method
      * @param array $data
      * @throws DataNotValidException
      */
     public function validateManyOrFail(array $data);

     /**
      * Validates a multidimensional or throws exception
      * It also stores all the errors. Then you can retrieve them with the
      * getValidationErrors() method
      * @param array $data
      * @param array $rules
      * @throws DataNotValidException
      */
     public function validateManyWithCustomRulesOrFail(array $data, array $rules);

    /**
     * Returns the errors generated by the validate methods
     * with the keys "messages" and "failed"
     * If you used validateMany it will be a multidimensional array
     * @return array
     */
    public function getValidationErrors();

    /**
    * Return the messages key from the getValidationErrors method
    * If used after validateMany it will be a multidimensional array
    * @return array
    */
    public function getValidationMessages();

    /**
    * Return the failed key from the getValidationErrors method
    * If used after validateMany it will be a multidimensional array
    * @return array
    */
    public function getValidationFailures();

     /**
      * @param int $id
      * @return boolean
      */
     public function delete($id);

     /**
      * @param int $id
      * @throw EntityNotFoundException
      */
     public function deleteOrFail($id);

     /**
      * Delete all the rows
      * @return int Number of deleted rows
      */
     public function deleteAll();
```

Timestamps
----------

[](#timestamps)

You can add timestamps adding the $timestamps = true property:

```
class DownloadRepository extends LaravelRepository
{
    protected $timestamps = true;
}
```

By default it will manage created\_at and updated\_at fields. You can override the created and updated fields using the following properties:

```
protected $stamp_create = 'created_at';
protected $stamp_update = 'updated_at';
```

Validation
----------

[](#validation)

You can validate your data with the validate methods. Specify the rules of your repository in the rules property:

```
class UserArrayRepository extends LaravelRepository {

    protected $connection = 'default';
    protected $tableName  = 'users';
    protected $rules      = array(
        'name' => 'required|min:5|unique:users',
        'age'  => 'required|integer|between:0,120',
    );
}
```

Examples:

```
if ($this->arrayRepository->validate($validData)) {
    //The data is valid
}
else {
    //The data is not valid
    //You can get the validation failed or messages this way:
    $errors = $this->arrayRepository->getValidationErrors()
    //$errors['messages'] Contains an array with the validation messages
    //$errors['failed'] Contains an array with the failed rules
}
```

Extending the repository with your custom methods
-------------------------------------------------

[](#extending-the-repository-with-your-custom-methods)

You can grab the builder instance with

```
$this->getBuilder()
```

to create your custom repository methods.

### Example

[](#example-1)

```
class MyUserRepository extends LaravelRepository
{
    public function getActiveUsers()
    {
        $result = $this->getBuilder()->whereActive(true)->get();

        //Builder returns an objects array so you can use the following method
        //to convert an array of objets to array
        return $this->objectsToArray($result);
    }
}
```

A best practice would be to create a new interface for MyUsersRepository with all of the new methods that you are going to add.

```
interface MyUserRepositoryInterface
{
    /**
    * @return array
    */
    public function getActiveUsers();
}
```

And then implement it on your repository:

```
class MyUserRepository extends LaravelRepository implements MyUserRepositoryInterface
{
    /**
    * {@inheritdoc}
    */
    public function getActiveUsers()
    {
        $result = $this->getBuilder()->whereActive(true)->get();

        //In order to return the data with the current fetcher use the getFetcher() method like this:
        return $this->getFetcher()->fetchMany($result);

        //If you are returning only one entity use fetch method instead
        return $this->getFetcher()->fetch();
    }
}
```

So if you want to change the implementation you would need to implement the MyUsersRepositoryInterface and LaravelRepositoryInterface.

Future
======

[](#future)

More features coming soon

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

11

Last Release

4287d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2385242?v=4)[Carlos G.G.](/maintainers/carlosgoce)[@carlosgoce](https://github.com/carlosgoce)

---

Top Contributors

[![carlosgoce](https://avatars.githubusercontent.com/u/2385242?v=4)](https://github.com/carlosgoce "carlosgoce (76 commits)")

---

Tags

laraveldatabasecollectionrepositoryrepositories

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/reynholm-laravel-repositories/health.svg)

```
[![Health](https://phpackages.com/badges/reynholm-laravel-repositories/health.svg)](https://phpackages.com/packages/reynholm-laravel-repositories)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[czim/laravel-repository

Repository for Laravel (inspired by and indebted to Bosnadev/Repositories)

52112.0k4](/packages/czim-laravel-repository)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
