|
| 1 | +# Laravel Repository Design Pattern |
| 2 | + |
| 3 | +## Contents |
| 4 | + |
| 5 | +- [What is the Repository Design Pattern?](#what-is-the-repository-design-pattern) |
| 6 | +- [Usage](#usage) |
| 7 | + |
| 8 | +## What is the Repository Design Pattern |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +To put it simply, it is an implementation of a brokering layer between the application and a data source. Neither party needs to be be aware of the other to perform their respective jobs which allows us to have a decoupled architecture which in turn helps in the scaling of the application in the big leagues without having hard dependencies. |
| 13 | + |
| 14 | +## Is it the magic bullet |
| 15 | + |
| 16 | +Well, no it is not. Like every design pattern it has its ups and downs, pros and cons. |
| 17 | + |
| 18 | +### Pros: |
| 19 | + |
| 20 | +- Separation of concerns; the application need not know about or track any or all data sources. |
| 21 | +- Allows easy unit testing as the repositories are bound to interfaces which are injected into classes at run time. |
| 22 | +- DRY (Dont Repeat Yourself) design, the code to query and fetch data from data source(s) is not repeated. |
| 23 | + |
| 24 | +### Cons: |
| 25 | + |
| 26 | +- Adds another layer of abstraction which adds a certain level of complexity making it an overkill for small applications. |
| 27 | + |
| 28 | +## Source |
| 29 | + |
| 30 | +- [Repository Design Pattern Demystified](https://www.sitepoint.com/repository-design-pattern-demystified/) |
| 31 | +- [Use the Repository Design pattern in a Laravel application](https://medium.com/employbl/use-the-repository-design-pattern-in-a-laravel-application-13f0b46a3dce) |
| 32 | + |
| 33 | +# Usage |
| 34 | + |
| 35 | +This package provide a command-line interface for you to create repository in your **Laravel** application. |
| 36 | + |
| 37 | +## Installation |
| 38 | + |
| 39 | +Require `pp-spaces/laravel-repository` package to your laravel installation |
| 40 | + |
| 41 | +```sh |
| 42 | +composer require pp-spaces/laravel-repository |
| 43 | +``` |
| 44 | + |
| 45 | +## Make a repository |
| 46 | + |
| 47 | +Run the following command to generate repository: |
| 48 | + |
| 49 | +```sh |
| 50 | +php artisan make:repository UserRepository |
| 51 | +``` |
| 52 | + |
| 53 | +To make model repository simply run: |
| 54 | + |
| 55 | +```sh |
| 56 | +php artisan make:repository UserRepository --model=User |
| 57 | +``` |
| 58 | + |
| 59 | +## Help |
| 60 | + |
| 61 | +``` |
| 62 | +Description: |
| 63 | + Create a new repository class |
| 64 | +
|
| 65 | +Usage: |
| 66 | + make:repository [options] [--] <name> |
| 67 | +
|
| 68 | +Arguments: |
| 69 | + name The name of the class |
| 70 | +
|
| 71 | +Options: |
| 72 | + -m, --model[=MODEL] Generate a repository for the given model. |
| 73 | + -h, --help Display this help message |
| 74 | + -q, --quiet Do not output any message |
| 75 | + -V, --version Display this application version |
| 76 | + --ansi Force ANSI output |
| 77 | + --no-ansi Disable ANSI output |
| 78 | + -n, --no-interaction Do not ask any interactive question |
| 79 | + --env[=ENV] The environment the command should run under |
| 80 | + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug |
| 81 | +``` |
0 commit comments