PHPackages                             dinkara/repobuilder - 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. dinkara/repobuilder

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

dinkara/repobuilder
===================

Create Migration,Model and Repository from console

v1.0.3(6y ago)26031MITPHPPHP ~5.6|~7.0

Since Oct 16Pushed 6y ago2 watchersCompare

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

READMEChangelogDependencies (4)Versions (28)Used By (1)

RepositoryBuilder
=================

[](#repositorybuilder)

Repobuilder is addon for PHP Laravel framework that implements Repository pattern and adds an extra level for database communication in our project architecture. Instead of accessing models and writing queries in your Controller classes or Models, you should place them here. This way you will create single access point with controlled set of functions to your database. Library also has necessary Laravel commands for easy creation of complete set of classes and files (migrations, models and repositories).

Main advantages are: \* Code reusability \* Code transparency \* Global usage \* Scalable

Requirements
------------

[](#requirements)

- Laravel ~5.5 or higher

Composer Install
----------------

[](#composer-install)

```
composer require dinkara/repobuilder
```

Publish service
---------------

[](#publish-service)

Add the service provider in `config/app.php`:

```
Dinkara\RepoBuilder\RepositoryBuilderServiceProvider::class,
```

For publishing new services you need to execute the following line

```
php artisan vendor:publish --provider="Dinkara\RepoBuilder\RepositoryBuilderServiceProvider"
```

Now you are ready to use new features. To check if everything is fine, execute following command

```
php artisan list
```

If you can see make:repo option everything is ready.

How to use command
------------------

[](#how-to-use-command)

Examples :

```
php artisan make:repo User
```

In order to use your repositories as standard Laravel services you need to add following lines to your app/Providers/AppServiceProvider.php. This will point interface to proper class so Laravel knows which class to load when that interface is initialized.

```
    public function register()
    {
    	/*
	   $repos represents array of all  you created with this library
	*/
        $repos = array(
            'User',
        );

        foreach ($repos as $idx => $repo) {
            $this->app->bind("App\Repositories\\{$repo}\I{$repo}Repo", "App\Repositories\\{$repo}\\Eloquent{$repo}");
        }
     }
```

This command will create new folder User under App\\Repositories and make two new files inside of them. Interface IUserRepo and class EloquentUser.

```
php artisan make:repo User --migation
```

This command will create same like first command but it will also create new migration with given name.

```
php artisan make:repo User --model
```

This command will create same like first command but it will also create new model with given name in App\\Models.

```
php artisan make:repo User --all
```

This command will create migration, model and necessary repository classes.

How to use repositories
-----------------------

[](#how-to-use-repositories)

Repositories created with this library can be used in Controllers, Services, Seeders or any other class in your Laravel application.

Basic example:

```
