From 90d65e96ceefffb78342f446917d06d7bd6b17bf Mon Sep 17 00:00:00 2001 From: Norlihazmey Ghazali Date: Fri, 23 Dec 2016 15:19:28 +0800 Subject: [PATCH 1/4] Update README.md --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d04c3ee..f21738b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,49 @@ -# arch -Laravel Package for Central repositories passing and receiving data between controller and model +# Arch Repositories +Laravel Package for Central repositories passing and receiving data from database. This package react as a bridge between Controller, Model and database. All the reusable code should located in one place and called when needed. + +# Installation +1) Package can be installed using composer, just require it : + + composer require arch/repositories + +2) After install, add `ArchServiceProvider` to provider array in `config/app.php` as follow : + + 'providers' => [ + ............ + Arch\Repositories\ServiceProvider\ArchServiceProvider::class + ]; + +# Usage + +Before everything can be used, we must create `Canal` and `Repositories` for the application and make use of trait class for the `Model`. + +## 1) Generate Repositories + +Repositories is a normal php class having all the functionalities to play with the `Laravel Query Builder` for database querying. You can find out all the available method at `Available method` section. Use below command for generating `repositories` : + + php artisan shareable:repositories --model= + + eg : + + php artisan shareable:repositories UserRepositories --model=User + + **RepositoriesName** - Repositories name + + **modelName** - Model name. This model were tied with repositories. + + This command will create `Repositories` file inside `App\Repositories` directory on the fly. One repositories should have one model that tied with it. For ease of use, create repositories with descriptive name. `Eg : UserRepositories`, then we know that this repositories belongs to `User` model. + +## 2) Generate Canal + +Canal is a normal php class having all the reusable method that were created to call inside the `controller`. We didn't call the model directly inside `controller` instead we use this `Canal` class for that purpose to manage data passing/retreiving. This class should have methods that call `Repositories`'s method. + + php artisan shareable:canal + + eg : + + php artisan shareable:canal UserModuleCanal + + **CanalName** - Canal name. + + This command will create `Canal` file inside `App\Canal` directory on the fly. This class should contains all the reusable code. As example we have `UserModule` for simple/complex crud operation, user permission and anything else. Then, all the methods can be placed inside `UserModuleCanal`, and `UserModuleCanal` can call any of `Repositories`'s method inside of it. + From 3246f9b9d8ce70d34e9e488ab230c5f38023cc97 Mon Sep 17 00:00:00 2001 From: Norlihazmey Ghazali Date: Fri, 23 Dec 2016 15:38:09 +0800 Subject: [PATCH 2/4] Update README.md --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f21738b..49e48a7 100644 --- a/README.md +++ b/README.md @@ -45,5 +45,26 @@ Canal is a normal php class having all the reusable method that were created to **CanalName** - Canal name. - This command will create `Canal` file inside `App\Canal` directory on the fly. This class should contains all the reusable code. As example we have `UserModule` for simple/complex crud operation, user permission and anything else. Then, all the methods can be placed inside `UserModuleCanal`, and `UserModuleCanal` can call any of `Repositories`'s method inside of it. + This command will create `Canal` file inside `App\Canal` directory on the fly. This class should contains all the reusable code. As example we have `UserModule` for simple/complex crud operation, user permission and anything else. Then, all the methods can be placed inside `UserModuleCanal`, and `UserModuleCanal` can call any of `Repositories`'s method inside of it. Later on, if we have two controller for the `Web` application and `Api` stuff with the same behaviour, we can just call the `UserModuleCanal` for both `controller` as they all share the same functionality. + +## 3) Make use of traits inside Model + +Last, include trait `Arch\Repositories\Tools\Instantiate` inside our `Model` that tied with the `Repositories` as follow : + +```Php + Date: Fri, 23 Dec 2016 16:10:48 +0800 Subject: [PATCH 3/4] Update README.md --- README.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 49e48a7..aa8138e 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,27 @@ # Arch Repositories Laravel Package for Central repositories passing and receiving data from database. This package react as a bridge between Controller, Model and database. All the reusable code should located in one place and called when needed. -# Installation +# Package Installation 1) Package can be installed using composer, just require it : composer require arch/repositories 2) After install, add `ArchServiceProvider` to provider array in `config/app.php` as follow : - 'providers' => [ - ............ - Arch\Repositories\ServiceProvider\ArchServiceProvider::class - ]; +```Php +'providers' => [ + ............ + Arch\Repositories\ServiceProvider\ArchServiceProvider::class +]; +``` -# Usage +# Canal, Repositories and Model Installation Before everything can be used, we must create `Canal` and `Repositories` for the application and make use of trait class for the `Model`. ## 1) Generate Repositories -Repositories is a normal php class having all the functionalities to play with the `Laravel Query Builder` for database querying. You can find out all the available method at `Available method` section. Use below command for generating `repositories` : +`Repositories` is a normal php class having all the functionalities to play with the `Laravel Query Builder` for database querying. You can find out all the available method at `Available method` section. Use below command for generating `repositories` : php artisan shareable:repositories --model= @@ -64,7 +66,91 @@ class User extends Model { } ``` -Done! +Follow these 3 steps for another module. Done! + +# Usage Example + +1) First, include `Canal` class inside `Controller`, eg : `UserController` : + +```Php +userModule = new UserCanal; + } + // retrieving all users + public function index () { + + dd( $this->userModule->getAllUser() ); + + } +} +``` + +2) Create reusable code inside `Canal` class, eg : `UserModuleCanal` : + +```Php +all(); // call UserRepo method and pass data back to Controller + + } + +} +``` + +3) Simple example of Repositories, eg : `UserRepositories` : + +```Php +model = User::getInstance(); + } + + // At here we didn't create all() method, basically we didnt + // create any method inside this repositories + // as all the laravel Query method already + // available inside this repositories + // by include this BaseShareables class + // unless you need complex query that BaseShareables didnt provided for you + + // You can do any custom query from database in here + // by creating custom method, later on, we can call + // this method inside `Canal` class +} + From 26586b01d29991ad51eea158289aa801efa8e10a Mon Sep 17 00:00:00 2001 From: Norlihazmey Ghazali Date: Fri, 23 Dec 2016 16:18:04 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index aa8138e..0b6286f 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,18 @@ class UserRepositories extends BaseAbstract { // by creating custom method, later on, we can call // this method inside `Canal` class } +``` + +4) Map the route to that controller and you're good to go. + +# Supports + +- Well, just open an issues + +# Authors + +- [Norlihazmey](https://github.com/metallurgical) +- [Afiq Abdullah](https://github.com/AfiqAbdullah)