PHPackages                             inz/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. inz/repository

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

inz/repository
==============

Repository pattern file generator for laravel projects

v1.1(6y ago)15[3 PRs](https://github.com/joeloudjinz/laravel-repository/pulls)MITPHPPHP &gt;=7.0.2

Since Nov 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/joeloudjinz/laravel-repository)[ Packagist](https://packagist.org/packages/inz/repository)[ RSS](/packages/inz-repository/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/e3f34747a5b11a845c03b7dbb5bd90bd33d3414924190ee2b8ad35f171c245bb/68747470733a2f2f73656d6170686f726563692e636f6d2f6170692f76312f70726f6a656374732f62373461633438652d313363652d346530332d616231322d3233366639383963396333372f333030393038322f62616467652e737667)](https://semaphoreci.com/joe-inz-94/laravel-repository)[![Packagist Version](https://camo.githubusercontent.com/4ba2fa11f30ccd829e99224c070854bd8aaee98087927ef85760aa87f6d5b300/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e7a2f7265706f7369746f7279)](https://camo.githubusercontent.com/4ba2fa11f30ccd829e99224c070854bd8aaee98087927ef85760aa87f6d5b300/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e7a2f7265706f7369746f7279)[![Packagist](https://camo.githubusercontent.com/3e43f9ffe81b259a3b94bef1edc60be8784d9ac3452a7e3d8be297ac7f23db0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696e7a2f7265706f7369746f7279)](https://camo.githubusercontent.com/3e43f9ffe81b259a3b94bef1edc60be8784d9ac3452a7e3d8be297ac7f23db0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696e7a2f7265706f7369746f7279)[![PHP from Packagist](https://camo.githubusercontent.com/116eab954f217480ae1b60f3df68f163fef8720c831982926c17642a9b291ca5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e7a2f7265706f7369746f7279)](https://camo.githubusercontent.com/116eab954f217480ae1b60f3df68f163fef8720c831982926c17642a9b291ca5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e7a2f7265706f7369746f7279)[![GitHub](https://camo.githubusercontent.com/00894382423587e610b2668a1705513b397677327417684c63af563069c69c69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f656c6f75646a696e7a2f6c61726176656c2d7265706f7369746f7279)](https://camo.githubusercontent.com/00894382423587e610b2668a1705513b397677327417684c63af563069c69c69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f656c6f75646a696e7a2f6c61726176656c2d7265706f7369746f7279)[![GitHub code size in bytes](https://camo.githubusercontent.com/d2bef30e63f719d00d1b8fb3b9fa5f3dde67896816a74c9a7fc9c2595ea13ca2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6a6f656c6f75646a696e7a2f6c61726176656c2d7265706f7369746f7279)](https://camo.githubusercontent.com/d2bef30e63f719d00d1b8fb3b9fa5f3dde67896816a74c9a7fc9c2595ea13ca2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6a6f656c6f75646a696e7a2f6c61726176656c2d7265706f7369746f7279)[![GitHub repo size](https://camo.githubusercontent.com/36ac732fc8d13412e5d8b429a2b35a127dac1667a5f5a08f35e5dc57abfaa776/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f6a6f656c6f75646a696e7a2f6c61726176656c2d7265706f7369746f7279)](https://camo.githubusercontent.com/36ac732fc8d13412e5d8b429a2b35a127dac1667a5f5a08f35e5dc57abfaa776/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f6a6f656c6f75646a696e7a2f6c61726176656c2d7265706f7369746f7279)

Repository pattern generator
============================

[](#repository-pattern-generator)

This package helps you get started quickly to use **repository pattern** in your next, or current, laravel project because after watching those laracon videos (which by the way are A LOT :p) that talks about design patterns and SOLID principals you became all hipped to try and adapt them, at least i'm :D.

---

Content
-------

[](#content)

- [Introductory](#introductory)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Generating contract &amp; implementation](#generating-1)
    - [Binding contract to implementation](#generating-2)
- [Functionalities](#functionalities)
    - [Repository abstract class](#func-1)
    - [Methods](#func-2)
    - [Soft-deleted records](#func-3)
- [Contribution](#contribution)

---

Introductory
--------------------------------------------------

[](#introductory)

Using this package will help you spend more time focusing on your application's logic by taking care of generating and implementing a layer that sits between the logic and the database. It generates:

- **Repository Contract**: which is an empty interface that can be used to add custom methods to the repository implementation class so you can extend the functionalities, it's also used during binding process.
- **Implementation Class**: a class in which the repository logic reside, it implements the generated contract.

> **Note**: for now, the minimum laravel version this package is tested on is **5.5**

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

[](#installation)

```
composer require inz/repository
```

if you using **laravel 5.4 and below**, you need to add the package's service provider in `config/app.php`

```
'providers' => [
    ...
    Inz\RepositoryServiceProvider::class,
    ...
],
```

then, you need to publish the configuration file so the package can do it's work properly:

```
php artisan vendor:publish --tag=inz-repository
```

this will copy the package's configuration file into config folder of the application, more about it in [configuration](#configuration) section

Configuration
----------------------------------------------------

[](#configuration)

The configuration file for the package contains a group of settings which can be modified to satisfy your needs, they have a hopefully clear comments that describes their purposes.

```
    /*
    |--------------------------------------------------------------------------
    | Base Values
    |--------------------------------------------------------------------------
    | this array give you the ability to define base path & namespace to be used by the package,
    | path is used to create the base directory in which all generated files are stored, on
    | the other hand, namespace is used to define the base namespace for those files.
    |
    | Note that (in the comments) the anti-slash for namespace required when defining it's value.
    |
     */
    'base' => [
        'path' => app_path(), // 'app folder' which is the best choice
        'namespace' => app()->getNamespace(), // 'App\' which is the best choice
        'providers' => [
            'path' => app_path(),
            'namespace' => app()->getNamespace(),
        ],
    ],
```

- **path** is used to create root directory for the files.
- **namespace** is used to set a namespace for the file.
- **providers** array where you set the base path and namespace of the providers in your application so the package can determine where and under what it should define the repository service provider.

```
    /*
    |--------------------------------------------------------------------------
    | Namespaces
    |--------------------------------------------------------------------------
    | this array define the namespaces related to each category of the generated classes
    | by the package, you can re-define these values to control under what namespace
    | the these classes should reside.
    |
    | Note that anti-slash in the end is not set so make sure you don't add it.
     */
    'namespaces' => [
        'contracts' => 'Repositories\Contracts',
        'implementations' => 'Repositories\Implementations',
    ],
```

- **namespaces** array determines the namespaces for different files, note that `App\` is not present because it will be added if specified.

```
    /*
    |--------------------------------------------------------------------------
    | Paths
    |--------------------------------------------------------------------------
    | this array defines the path for each category of the generated classes by the package,
    | you can re-define these values to control where the files should be stored, by
    | default they are stored in the application directory.
    |
    | Note that anti-slash in the end is not set so make sure you don't add it.
     */
    'paths' => [
        'contracts' => 'Repositories/Contracts',
        'implementations' => 'Repositories/Implementations',
    ],
```

- **paths** array determines the paths for different files, `Repositories` represent the root directory for them and what goes after the slash is the directory for those files, note that `app/` is not present because it will be added if specified.

Usage
------------------------------------

[](#usage)

### Generating contract &amp; implementation

[](#generating-contract--implementation)

To generate a full scaffold, you run

```
// the pattern
php artisan make:repository Model

// for a model in app directory
php artisan make:repository Post

// for a model in Models folder
php artisan make:repository Models/Post

// for a model in Models folder in a subdirectory
php artisan make:repository Models/Blog/Post
```

#### Notes

[](#notes)

- if the model doesn't exist, you will be asked if you want to create it, if so it will be created.
- If one of the other files exist already you will be asked to override it, if so it will, thus **be careful** about this situation to avoid losing written code.
- This command will bind the classes also.
- Don't forget to register the `RepositoryServiceProvider` in `app.php` after it is generated.

### Binding contract to implementation

[](#binding-contract-to-implementation)

to bind a contract class to an implementation of a certain model, use the command:

```
php artisan bind:repository Model
```

- using the model name, the package can determine the corresponding contract and implementation classes > Currently, the package will not check if the classes (model, contract or implementation) exist, this will be fixed in the upcoming version.
- if the service provider doesn't exist it will create one
- if the repository is already bound it won't complete the process.

Functionalities
--------------------------------------------------------

[](#functionalities)

### Repository abstract class

[](#repository-abstract-class)

In `Inz\Base\Abstractions\Repository` you can find the implementation of `Inz\Base\Interfaces\RepositoryInterface` that describes the methods used to access the database.

PropertiesWhy`protected $model;`model instance used to query data`protected $attributes;`attributes list of the model, also the list of columns of the table, excluding the ones in `$excludedColumns`.`protected $excludedColumns;`to define the columns that will be excluded when the repository object operates on the table, to add other columns to this array just override it in your repository implementation class.### Methods

[](#methods)

Here is the list of available methods of the repository class:

> **Note**: Repository class should be implemented the way you desire, so use the interface to define the blueprint for it and implement additional methods or override existing ones in the concrete class.

MethodParametersReturnDescriptionall();array `cols` default `['*']`Collectionsimilar to `all()` of eloquent modelfirst();Model instance or nullsimilar to `first()` of eloquent modelfind();mixed `id`Model instance or nullsimilar to `find()` of eloquent modelfindWhere();String `column`, mixed `value` &amp; String `operator`Collectionfinds all records that match the condition of where clausefindFirstWhere();String `column`, mixed `value` &amp; String `operator`Model instance or nullfinds the first record that matches the condition of where clausepaginate();int `count` default `10`LengthAwarePaginator instancesimilar to `paginate()` of eloquent modelsave();array `data = [column => value]`booleancreates a new instance based on the passed data and persist it to storageupdate();int `id` &amp; array `data = [column => value]`booleanupdates a record based on the passed data and persist it to storage, if the record doesn't exist `false` is returneddelete();int `id`booleansimilar to `delete()` of eloquent modelcount();intsimilar to `count()` of eloquent model### Soft deleted records

[](#soft-deleted-records)

To handle trashed records of the table (if using soft delete trait in the model), use trait `Inz\Base\Traits\TrashedOperations` in repository implementation class, it contains this set of methods:

MethodParametersReturnDescriptionallTrashed();array `cols` default `['*']`Collectionreturns soft-deleted records onlyallWithTrashed();array `cols` default `['*']`Collectionreturns the whole records of the tablefirstTrashed();Model instance or nullfetches the first record from trashed ones onlyfindTrashed();mixed `id`Model instance or nullfetches a record of the passed id from trashed ones onlyfindWithTrashed();mixed `id`Model instance or nullfetches a record of the passed id from the whole tablecountTrashed();intreturns the count of trashed records in the tablecountWithTrashed()intreturns the count of all records in the tablerestore();mixed `id`booleanrestore a soft-deleted record in trashed oneserase();mixed `id`booleanpermanently deletes a record from the tableContribution
--------------------------------------------------

[](#contribution)

Feel free to make any pull request, any contribution is welcomed. If you encountered a problem, use the issues section.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.2% 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

3

Last Release

2361d ago

Major Versions

v0.9 → v1.02019-11-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33733877?v=4)[Abdullah Addoun](/maintainers/joeloudjinz)[@joeloudjinz](https://github.com/joeloudjinz)

---

Top Contributors

[![joeloudjinz](https://avatars.githubusercontent.com/u/33733877?v=4)](https://github.com/joeloudjinz "joeloudjinz (122 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

artisan-commandlaravelpackagerepository-patternsolid-principleslaravelrepository patternsolidprincipals

### Embed Badge

![Health badge](/badges/inz-repository/health.svg)

```
[![Health](https://phpackages.com/badges/inz-repository/health.svg)](https://phpackages.com/packages/inz-repository)
```

###  Alternatives

[stephenjude/filament-blog

Filament Blog Builder

20317.8k](/packages/stephenjude-filament-blog)

PHPackages © 2026

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