2017 © Pedro Peláez
 

library repo

Easily generate the Repository Pattern in Laravel

image

io-digital/repo

Easily generate the Repository Pattern in Laravel

  • Wednesday, December 6, 2017
  • by io-digital
  • Repository
  • 1 Watchers
  • 3 Stars
  • 905 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 30 Versions
  • 9 % Grown

The README.md

Repo

This package creates scaffolding to implement the Repository pattern., (*1)

Install

Repo supports package auto discovery for Laravel, (*2)

composer require io-digital/repo, (*3)

Add the ServiceProvider to your config/app.php providers array:, (*4)

``` php IoDigital\Repo\RepoServiceProvider::class,, (*5)


Then run the following artisan command: ``` bash $ php artisan vendor:publish --provider="IoDigital\Repo\RepoServiceProvider"

This will create the following folder structure in your app/ folder:, (*6)

  • Models
    • Concrete
      • Eloquent
      • _AbstractEloquentRepository.php
    • Contracts
      • Repositories
      • _RepositoryInterface.php
    • Objects

Note that _AbstractEloquentRepository.php and _RepositoryInterface.php are named as such to avoid existing files being overwritten. In the case of a new installation, these files can simply be renamed to AbstractEloquentRepository.php and RepositoryInterface.php, respectively. If these files already exist, on the other hand, please take care to manually merge the newly published files with the existing ones., (*7)

Usage

After installing the package the artisan command repo:create should be available., (*8)

To create the repository structure for your object run the command:, (*9)

``` bash $ php artisan repo:create Post, (*10)


This will create the following files: - Models/Objects/Post.php - Models/Contracts/Repositories/PostRepository.php - Models/Concrete/Eloquent/EloquentPostRepository.php It will also add the bindings in your `AppServiceProvider.php` file: ``` php $this->app->bind( 'App\Models\Contracts\Repositories\PostRepository', // Repository (Interface) 'App\Models\Concrete\Eloquent\EloquentPostRepository' // Eloquent (Class) );

Then in your Controller it's simply:, (*11)

``` php ... use App\Models\Contracts\Repositories\PostRepository;, (*12)

..., (*13)

protected $model;, (*14)

public function __construct(PostRepository $repo) { $this->model = $repo; }, (*15)


### Options * `-m` or `--m` * `-c` or `--c` Use the `-m` option to create a migration file for your object: ``` bash $ php artisan repo:create Post -m

Use the -c option to create a resource controller for your object:, (*16)

``` bash $ php artisan repo:create Post -c, (*17)


All together now: ``` bash $ php artisan repo:create Post -m -c

The repository interface provides the following methods:, (*18)

``` php public function make($with = [], $orderBy = []);, (*19)

public function all($with = [], $orderBy = [], $columns = ['*']);, (*20)

public function find($id, $relations = []);, (*21)

public function findBy($attribute, $value, $columns = ['*']);, (*22)

public function findAllBy($attribute, $value, $columns = ['*']);, (*23)

public function findWhere($where, $columns = ['*'], $or = false);, (*24)

public function findWhereIn($field, array $values, $columns = ['*']);, (*25)

public function paginate($perPage = 25, $columns = ['*']);, (*26)

public function simplePaginate($limit = null, $columns = ['*']);, (*27)

public function create($attributes = []);, (*28)

public function edit($id, $attributes = []);, (*29)

public function delete($id);, (*30)


The implementations can found in `Models/Concrete/AbstractEloquentRepository.php` Example usage for the find functions: ```php //returns the model with the relationship as a paginated collection $data = $this->model->make(['relation'])->paginate(); //returns with ->first() $data = $this->model->findBy('title', $title); //returns with ->get() $data = $this->model->findAllBy('category', $category); //returns with ->get() $data = $this->model->findWhere([ 'category' => $category, ['year', '>' , $year], ['name', 'like', "%$name%"], ['surname', 'like', '%nes'] ]); $data = $this->model->findWhereIn('id', [1, 2, 3]) ->get(['name', 'email']);

Change log

Please see CHANGELOG for more information what has changed recently., (*31)

Testing

bash $ composer test, (*32)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*33)

TODO

Clean up code, (*34)

License

The MIT License (MIT). Please see License File for more information., (*35)

The Versions

06/12 2017

dev-master

9999999-dev https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

29/06 2017

v1.1.21

1.1.21.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

23/06 2017

v1.1.20

1.1.20.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

23/06 2017

dev-feature/package-autodiscovery

dev-feature/package-autodiscovery https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

14/06 2017

v1.1.19

1.1.19.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

14/06 2017

dev-feature/controller-creation

dev-feature/controller-creation https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

06/09 2016

dev-feature/update-repo-functions

dev-feature/update-repo-functions https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

06/09 2016

v0.1.18

0.1.18.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

06/09 2016

v1.1.18

1.1.18.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

06/09 2016

v0.1.17

0.1.17.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

06/09 2016

v0.1.16

0.1.16.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

06/09 2016

v0.1.15

0.1.15.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

02/09 2016

v0.1.14

0.1.14.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

02/09 2016

v0.1.13

0.1.13.0 https://github.com/io-digital/repo

Easily generate the Repository Pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

19/07 2016

v0.1.12

0.1.12.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

19/07 2016

dev-feature/where-in

dev-feature/where-in https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

13/07 2016

v0.1.11

0.1.11.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

13/07 2016

v0.1.10

0.1.10.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

12/07 2016

v0.1.9

0.1.9.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

12/07 2016

v0.1.8

0.1.8.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

22/06 2016

v0.1.7

0.1.7.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

15/06 2016

v0.1.6

0.1.6.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

10/06 2016

v0.1.5

0.1.5.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

10/06 2016

v0.1.4

0.1.4.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

10/06 2016

v0.1.3

0.1.3.0 https://github.com/io-digital/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

03/06 2016

v0.1.2

0.1.2.0 https://github.com/garethnic/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

30/05 2016

v0.1.1

0.1.1.0 https://github.com/garethnic/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

11/03 2016

v0.1.0

0.1.0.0 https://github.com/garethnic/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

11/03 2016

dev-feature/usage-update

dev-feature/usage-update https://github.com/garethnic/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo

11/03 2016

dev-feature/progress-bar

dev-feature/progress-bar https://github.com/garethnic/repo

Scaffold repository pattern in Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel repository pattern repo