PHPackages                             angkosal/repository - 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. angkosal/repository

ActiveLibrary

angkosal/repository
===================

Laravel repository generator.

332PHP

Since Dec 12Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel 5 Repository
====================

[](#laravel-5-repository)

Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain.

You want to know a little more about the Repository pattern? [Read this great article](http://bit.ly/1IdmRNS).

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
    - [Composer](#composer)
    - [Laravel](#laravel)
- [Methods](#methods)
    - [RepositoryInterface](#angkosalrepositorycontractsrepositoryinterface)
    - [CriteriaInterface](#angkosalrepositorycontractscriteriainterface)
- [Usage](#usage)
    - [Create a Model](#create-a-model)
    - [Create a Repository](#create-a-repository)
    - [Generators](#generators)
    - [Use methods](#use-methods)
    - [Create a Criteria](#create-a-criteria)
    - [Using the Criteria in a Controller](#using-the-criteria-in-a-controller)

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

[](#installation)

### Composer

[](#composer)

Execute the following command to get the latest version of the package:

```
composer require angkosal/repository

```

### Laravel

[](#laravel)

#### &gt;= laravel5.5

[](#-laravel55)

ServiceProvider will be attached automatically

#### Other

[](#other)

In your `config/app.php` add `Angkosal\Repository\RepositoryServiceProvider::class` to the end of the `providers` array:

```
'providers' => [
    ...
    Angkosal\Repository\RepositoryServiceProvider::class,
],
```

Publish Configuration

```
php artisan vendor:publish --provider="Angkosal\Repository\RepositoryServiceProvider" --tag="config"
```

Methods
-------

[](#methods)

### Angkosal\\Repository\\Contracts\\RepositoryInterface

[](#angkosalrepositorycontractsrepositoryinterface)

- all();
- first();
- find($id);
- findWhere($column, $value);
- findWhereFirst($column, $value);
- findWhereLike($column, $value);
- paginate($perPage = 10);
- create(array $properties);
- update($id, array $properties);
- delete($id);

### Angkosal\\Repository\\Contracts\\CriteriaInterface

[](#angkosalrepositorycontractscriteriainterface)

- withCriteria($criteria)

Usage
-----

[](#usage)

### Create a Model

[](#create-a-model)

Create your model normally, but it is important to define the attributes that can be filled from the input form data.

```
namespace App;

class Post extends Eloquent { // or Ardent, Or any other Model Class

    protected $fillable = [
        'title',
        'author',
        ...
     ];

     ...
}
```

### Create a Repository

[](#create-a-repository)

```
namespace App\Repositories\Eloquent;

use App\Post;
use Angkosal\Repository\Eloquent\AbstractRepository;

class EloquentPostRepository extends AbstractRepository {

    /**
     * Specify Model class name
     *
     * @return string
     */
    function model()
    {
        return Post::class;
    }
}
```

### Generators

[](#generators)

Create your repositories easily through the generator.

#### Config

[](#config)

You must first configure the storage location of the repository files. By default is the "app" folder and the namespace "App". Please note that, values in the `paths` array are acutally used as both *namespace* and file paths. Relax though, both foreward and backward slashes are taken care of during generation.

```
