matthewbdaly / laravel-repositories
A base repository class and interface, together with a caching decorator. Extend them for use in your own projects.
Installs: 1 191
Dependents: 5
Suggesters: 0
Security: 0
Stars: 12
Watchers: 4
Forks: 1
Open Issues: 0
Requires (Dev)
- matthewbdaly/artisan-standalone: 0.0.*
- mockery/mockery: ^1.0
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^6.4
- psy/psysh: ^0.8.14
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.1
README
A base repository class and interface, together with a caching decorator. Extend them for use in your own projects.
The base interface is Matthewbdaly\LaravelRepositories\Repositories\Interfaces\AbstractRepositoryInterface
. Your repositories should have interfaces that extend this, to facilitate type-hinting them.
This interface is implemented by both the abstract decorator Matthewbdaly\LaravelRepositories\Repositories\Decorators\BaseDecorator
and the abstract repository Matthewbdaly\LaravelRepositories\Repositories\Base
. Again, you should extend these classes to create your own repositories and decorators. You can then resolve these interfaces in your own service provider as follows:
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { $this->app->singleton('App\Repositories\Interfaces\ExampleRepositoryInterface', function () { $baseRepo = new \App\Repositories\EloquentExampleRepository(new \App\Example); $cachingRepo = new \App\Repositories\Decorators\ExampleDecorator($baseRepo, $this->app['cache.store']); return $cachingRepo; }); } }
Artisan tasks
This package implements the following Artisan tasks to help writing boilerplate:
make:repository
- Makes a repository for the model passed, iephp artisan make:repository Foo
. Pass the--all
flag to also create the contract and decorator.make:repository:contract
- Makes a contract for the model passed, iephp artisan make:repository:contract Foo
make:repository:decorator
- Makes a decorator for the model passed, iephp artisan make:repository:decorator Foo