PHPackages                             rafi021/repository-pattern - 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. rafi021/repository-pattern

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

rafi021/repository-pattern
==========================

A laravel pacakge for appling repository pattern in application

v1.0.0(2y ago)03MITPHPPHP ^8.1

Since Jul 19Pushed 2y agoCompare

[ Source](https://github.com/rafi021/repository-pattern)[ Packagist](https://packagist.org/packages/rafi021/repository-pattern)[ Docs](https://github.com/rafi021/repository-pattern)[ RSS](/packages/rafi021-repository-pattern/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

A laravel pacakge for appling repository pattern in application
===============================================================

[](#a-laravel-pacakge-for-appling-repository-pattern-in-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/73b8b0d690db90d304d4492affabda5f7f72e629bc70c958552873d8a9d2f443/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726166693032312f7265706f7369746f72792d7061747465726e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rafi021/repository-pattern)[![GitHub Tests Action Status](https://camo.githubusercontent.com/27c3a3d08d3f377bba9af07111e23b7eefa7202a0b750991a02f55d50e2bdbe7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726166693032312f7265706f7369746f72792d7061747465726e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/rafi021/repository-pattern/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ebad840e0b023ab72c731f5cc2033f20bd7647e9e14ee6db7b2333e7c3b5f1f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726166693032312f7265706f7369746f72792d7061747465726e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/rafi021/repository-pattern/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d15cd57e08de303ffe577aa40b1c5c42e63670cf8ab0951a7b42c5c1c3022aa1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726166693032312f7265706f7369746f72792d7061747465726e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rafi021/repository-pattern)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

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

[](#installation)

You can install the package via composer:

```
composer require rafi021/repository-pattern
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="repository-pattern-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="repository-pattern-config"
```

This is the contents of the published config file:

```
return [
];
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="repository-pattern-views"
```

Quick usage
-----------

[](#quick-usage)

This package overrides the default laravel `php artisan make:model User` command, and adds a few flags that can help you set up repository and service quickly.

```
// will genearate controller, factory, service, seeder, repository, resource and migration
php artisan make:model User --all

// use the service and repository flag to generate the class
php artisan make:model User --service --repository

// use the short form to generate model with service and repository
php artisan make:model User -sr -rt
```

You can also create only the repository, or service, or both:

```
php artisan make:repository User
// or
php artisan make:repository UserRepository

// or create together with a service
php artisan make:repository User --service
// or
php artisan make:repository UserRepository --service

// or create a service separately
php artisan make:service User
// or
php artisan make:service UserService
```

The `php artisan make:repository User` will generate two files. One for the interface, and one for the repository class. The interface is bound to it's counter part class automatically depending on the current implementation being used. If the implementation for an interface is not provided, you can provide one manually or otherwise, attempting to use the service will bring up an error.

Eloquent is the default implementation. Other implementations will be added in the future. This is because the package was mainly to simplify usage of the repository pattern in laravel. The classes created are:

```
// app/Repositories/Interfaces/UserRepository.php
