PHPackages                             arch/repositories - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. arch/repositories

ActiveLibrary[Database &amp; ORM](/categories/database)

arch/repositories
=================

Central repositories passing and receiving data between controller and model

1.5.1(9y ago)347MIT LicensePHP

Since Dec 23Pushed 9y ago2 watchersCompare

[ Source](https://github.com/metallurgical/arch)[ Packagist](https://packagist.org/packages/arch/repositories)[ RSS](/packages/arch-repositories/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

Arch Repositories
=================

[](#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.

Package 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
];
```

Canal, Repositories and Model Installation
==========================================

[](#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
------------------------

[](#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
-----------------

[](#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. 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
----------------------------------

[](#3-make-use-of-traits-inside-model)

Last, include trait `Arch\Util\Instantiate` inside our `Model` that tied with the `Repositories` as follow :

```
