PHPackages                             nfunwigabga/lara-repo - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nfunwigabga/lara-repo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nfunwigabga/lara-repo
=====================

Generate repositories in a Laravel application

v1.0.1(5y ago)011MITPHPPHP &gt;=7.2

Since Aug 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nfunwigabga/lara-repo)[ Packagist](https://packagist.org/packages/nfunwigabga/lara-repo)[ RSS](/packages/nfunwigabga-lara-repo/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

LaraRepo
========

[](#lararepo)

Larevel repository generator for Laravel version &gt;=6.0.

Installation
------------

[](#installation)

Require this package with composer:

```
composer require Nfunwigabga/lara-repo

```

Laravel uses package auto-discovery, so this package does not require you to manually register the service provider.

### Not using Auto-Discovery

[](#not-using-auto-discovery)

If you do not use Auto-Discovery, then you need to add the following service provider to your `config/app.php` file inside the Providers array:

```
Nfunwigabga\LaraRepo\ServiceProvider::class

```

### Publish the configuration

[](#publish-the-configuration)

The package comes with a configuration file, which you can publish using:

```
php artisan vendor:publish --provider="Nfunwigabga\LaraRepo\ServiceProvider"

```

The configuration defines the directory structure for your repositories and models.

Usage
-----

[](#usage)

The package comes with 2 commands that allow you to generate repositories and criteria.

### Generate a repository

[](#generate-a-repository)

Each repository is based on a model class. So when you generate the repository, you have to to provide the model class name (without the subdirectory)

```
php artisan make:repo {model name}

```

eg If you want to create a repository for the User model, you can do:

```
php artisan make:repo User

```

If the model does not already exist, you will be prompted whether you'd like to create it at the same time.

The above command will generate the following files:

```
// This is the concrete implementation of the repository
app/Repositories/UserRepository.php

// This is the interface that the repository class binds to.
app/Repositories/Contracts/IUser.php

// The model class if a User model did not exist before
app/User.php

// If you chose to generate a migration
database/migrations/xx_xx_xx_create_users_table.php

```

### Using the repository in your controller

[](#using-the-repository-in-your-controller)

Once a repository is generated, you get a number of base methods out-of-the-box that you can call directly. In a `UserController` class for instance, you can inject the repository contract like this and call the methods therein:

```
