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

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

okaybueno/laravel-repositories
==============================

A package that provides a neat implementation to integrate the Repository pattern in Laravel with Eloquent.

v2.0.1(5y ago)1816.1k6[3 issues](https://github.com/okaybueno/laravel-repositories/issues)MITPHPPHP &gt;=7.0

Since Aug 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/okaybueno/laravel-repositories)[ Packagist](https://packagist.org/packages/okaybueno/laravel-repositories)[ RSS](/packages/okaybueno-laravel-repositories/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (5)Versions (16)Used By (0)

IMPORTANT ❗
===========

[](#important-)

**This package has been discontinued and it won't receive any other updates. If you're using it please consider migrating to another solution – or fork it and depend on your own version of package.**

Using the repository pattern on Laravel does not feel good anymore. Laravel has evolved in a great way that made me embrace Eloquent at its maximum level. Comparing what Eloquent offers out of the box versus its implementation via the repository pattern, I found out that adding this intermediate layer ends up in providing *yet one more layer to maintain* that provides no value whatsoever to the final product or even during the process of development. I was wrong and I'm happy to be back to full Eloquent use.

---

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

[](#laravel-repositories)

A package that provides a neat implementation for integrating the Repository pattern with Laravel &amp; Eloquent.

[![Latest Version on Packagist](https://camo.githubusercontent.com/80c71b79580168e67fd77fa4a302448ed63ae33f2f4feab63cd29949423d97c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6b61796275656e6f2f6c61726176656c2d7265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/okaybueno/laravel-repositories)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/59b0c6627a7c41be94f78b366b02c9382e70ff5556e892c8d3aed8310fbe936e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f6b61796275656e6f2f6c61726176656c2d7265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/okaybueno/laravel-repositories)[![Total Downloads](https://camo.githubusercontent.com/18062b74e8749c951723f58de16168e4f8a8c5b9abfa17dc536fa9c841282411/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6b61796275656e6f2f6c61726176656c2d7265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/okaybueno/laravel-repositories)

Disclaimer
----------

[](#disclaimer)

This package was originally released [here](https://github.com/followloop/laravel-repositories), but since the future of that package is not clear, it has been forked and re-worked under this repository.

Goal
----

[](#goal)

Working with repositories can provide a great way to not only decouple your code but also separate concerns and isolate stuff, as well as separate and group responsibilities. Most of the time we will perform really generic actions on our database tables, like create, update, filter or delete.

However, using repositories is not always a good idea, specially with Laravel and its ORM, Eloquent, as it -sometimes- forces you to give up some great features in favor of *better architecture* (it depends). For some projects this may be an overkill and therefore is up to the developer to see if this level of complexity is needed or not.

This package aims to provide a boilerplate when implementing the Repository pattern on Laravel's Eloquent ORM. The way it provides it it's using a `RepositoryInterface` and a basic `Repository` implementation that is able to work with Eloquent models, providing basic methods that will cover 85% if the Database operations that you will probably do in your application.

Installation
------------

[](#installation)

1. Install this package by adding it to your `composer.json` or by running `composer require okaybueno/laravel-repositories` in your project's folder.
2. For Laravel 5.5 the Service provider is automatically registered, but if you're using Laravel 5.4, then you must add the provider to your `config/app.php` file: `OkayBueno\Repositories\RepositoryServiceProvider::class`
3. Publish the configuration file by running `php artisan vendor:publish --provider="OkayBueno\Repositories\RepositoryServiceProvider"`
4. Open the configuration file (`config/repositories.php`) and configure paths according to your needs.
5. Ready to go!

Usage
-----

[](#usage)

To start using the package, you just need to create a folder where you will place all your repository interfaces and the repository implementations and extend every single repository from the `EloquentRepository` class offered by the package.

The Eloquent model to be handled by the repository that you have created must also be injected via the Repo constructor.

The package then will try to load all the repository interfaces and bind them to a repository implementation according to the parameters specified in the `config/repositories.php` file.

Examples
--------

[](#examples)

*NOTE: Although the package includes a generator, please read all the docs carefully as some things may look just "magic".*

Let's consider we will have all our repositories in a folder called "Repositories", under a folder called "MyWebbApp" inside the "app" folder: app/MyWebApp/Repositories.

At the root of this folder we'll have all our interfaces following the next name convention: `[RepositoryName]Interface.php`

**NOTE**: It does not really matter the name that we use as long as we use "Interface" as suffix. This is important because the auto binder will try to find all files matching this pattern.

Inside this Repositories folder, we must have another folder called Eloquent, that will contain all our implementations for the repositories, following the next name convention: `[RepositoryName].php`.

We should have a structure like this:

```
+-- app
|   +-- MyApp
|       +-- Repositories
|           +-- UserRepositoryInterface.php
|           +-- RoleRepositoryInterface.php
|           +-- CommentRepositoryInterface.php
|           +-- PostRepositoryInterface.php
|           +-- Eloquent
|               +-- UserRepository.php
|               +-- RoleRepository.php
|               +-- CommentRepository.php
|               +-- PostRepository.php

```

Let's see what the `UserRepositoryInterface.php` and the `UserRepository.php` would have.

```
