2017 © Pedro Peláez
 

library repo

Scaffold repository pattern in Laravel

image

garethnic/repo

Scaffold repository pattern in Laravel

  • Tuesday, July 19, 2016
  • by garethnic
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

Repo

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

Install

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

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

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


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:, (*5)

  • Models
    • Concrete
      • Eloquent
      • AbstractEloquentRepository.php
    • Contracts
      • Repositories
      • RepositoryInterface.php
    • Objects

Usage

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

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

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


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:, (*9)

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

..., (*11)

protected $model;, (*12)

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


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

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

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

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

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

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

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

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

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

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

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

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

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


The implementations can found in `Models/Concrete/AbstractEloquentRepository.php` Example usage for the find functions: ```php //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., (*26)

Testing

bash $ composer test, (*27)

Contributing

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

TODO

Clean up code, (*29)

License

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

The Versions

19/07 2016

dev-master

9999999-dev 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

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

13/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