tripteki / laravelphp-repository
Trip Teknologi's Laravel.php Repository
1.0.0
2023-11-02 02:31 UTC
Requires
- php: ^8.0.2
Suggests
- laravel/framework: Required when using laravel framework (^9.0).
- laravel/lumen-framework: Required when using lumen framework (^9.0).
README
This package provides is an implementation of repository pattern for Lumen and Laravel.
Getting Started
Installation :
$ composer require tripteki/laravelphp-repository
How to use it :
- Initiate file
app/Contracts/Repository/IRepository.php
.
<?php namespace App\Contracts\Repository; use Tripteki\Repository\Contracts\Allable; use Tripteki\Repository\Contracts\Getable; use Tripteki\Repository\Contracts\Createable; use Tripteki\Repository\Contracts\Updateable; use Tripteki\Repository\Contracts\Deleteable; interface IRepository extends Allable, Createable, Deleteable { // };
- For QueryBuilder instance just initiate file
app/Repositories/QueryBuilder/MyRepository.php
.
<?php namespace App\Repositories\QueryBuilder; use App\Contracts\Repository\IRepository; use Tripteki\Repository\AbstractRepository; class MyRepository extends AbstractRepository implements IRepository { /** * @param array $querystring * @return mixed */ public function all($querystring = []) {} /** * @param array $data * @return mixed */ public function create($data) {} /** * @param int|string $identifier * @return mixed */ public function delete($identifier) {} };
- For Eloquent instance just initiate file
app/Repositories/Eloquent/MyRepository.php
.
<?php namespace App\Repositories\Eloquent; use App\Contracts\Repository\IRepository; use Tripteki\Repository\AbstractRepository; class MyRepository extends AbstractRepository implements IRepository { /** * @param array $querystring * @return mixed */ public function all($querystring = []) {} /** * @param array $data * @return mixed */ public function create($data) {} /** * @param int|string $identifier * @return mixed */ public function delete($identifier) {} };
- Initiate file
app/Providers/RepositoryServiceProvider.php
.
<?php namespace App\Providers; use Tripteki\Repository\RepositoryServiceProvider as ServiceProvider; class RepositoryServiceProvider extends ServiceProvider { /** * @var array */ protected $repositories = [ // For QueryBuilder // \App\Contracts\Repository\IRepository::class => \App\Repositories\QueryBuilder\MyRepository::class, // For Eloquent // \App\Contracts\Repository\IRepository::class => \App\Repositories\Eloquent\MyRepository::class, ]; };
- Put
App\Providers\RepositoryServiceProvider
to service provider configuration list.
Author
- Trip Teknologi (@tripteki)
- Hasby Maulana (@hsbmaulana)