PHPackages                             coliving/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. [Framework](/categories/framework)
4. /
5. coliving/repositories

ActiveLibrary[Framework](/categories/framework)

coliving/repositories
=====================

Flexable Laravel 6.x &amp; 7.x &amp; 8.x &amp; 9.x, 10.x &amp; 11.x Repository Library.

v1.4.0(1y ago)027.7k↓43.5%11MITPHPPHP ^7.3 | ^8.0 | ^8.1 | ^8.2 | ^8.3 | ^8.4

Since Jul 28Pushed 1y agoCompare

[ Source](https://github.com/dungnh/Repositories)[ Packagist](https://packagist.org/packages/coliving/repositories)[ Docs](https://github.com/dungnh/Repositories)[ RSS](/packages/coliving-repositories/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (13)Used By (1)

Repositories
============

[](#repositories)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2df34d4bb635df5955db839ab596a47e2aa17e84d7bb38896d46d8ab3e1178a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73656261737469616e2d626572632f7265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coliving/repositories)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/61cbcb4a67793c7fef5484dead43c736592cd4dd891f448de8d42c8ec4c4ce55/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f53656261737469616e426572632f5265706f7369746f726965732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/SebastianBerc/Repositories)[![Coverage Status](https://camo.githubusercontent.com/0090e2b5c368f5d67d560e589f7316a43c4df56ff3c844ca1a425dd28bb0e83e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f53656261737469616e426572632f5265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/SebastianBerc/Repositories/code-structure)[![SensioLabs Insight](https://camo.githubusercontent.com/976b171e4c2cd9b84e638969597fcfc7b237986202b4851ef1984c847e928cca/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f31363864616233352d613838392d346231632d393965372d3665306534346636313166362e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/168dab35-a889-4b1c-99e7-6e0e44f611f6)[![Quality Score](https://camo.githubusercontent.com/ae4bfdaeb0c437c43e70032e9334d1b9fd7db1365fd350ea7cddc5dc74fb5542/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f53656261737469616e426572632f5265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/SebastianBerc/Repositories)[![Total Downloads](https://camo.githubusercontent.com/0d04e7694735c84d7a0b52c9fa369dab37c131ef3561ace4d3eb9b4afb80b739/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73656261737469616e2d626572632f7265706f7369746f726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sebastian-berc/repositories)

Install
-------

[](#install)

Via Composer

```
$ composer require coliving/repositories
```

Usage
-----

[](#usage)

Make your own repository with extends the abstract `\SebastianBerc\Repositories\Repository` class and implement `takeModel` method:

```
class MyRepository extends \SebastianBerc\Repositories\Repository
{
    /**
     * Return fully qualified model class name.
     *
     * @return string
     */
    public function takeModel()
    {
        return MyModel::class
    }
}
```

#### Usage with Dependency Incjection

[](#usage-with-dependency-incjection)

Wherever Laravel provides dependency injection you can attach your repository like this:

```
class UsersController extends Controller
{
    /**
     * Contains users repository.
   	 *
     * @var UsersRepository
     */
    protected $repository;

	/**
	 * Creates a new instance of users controller.
	 *
	 * @param UsersRepository $repository
	 */
    public function __construct(UsersRepository $repository)
    {
        $this->repository = $repository;
    }
}
```

#### Usage without Dependency Injection

[](#usage-without-dependency-injection)

If you need a repository without dependency injection you can use the static method or just construct new instance like this:

```
	/**
	 * Creates a new users.
	 */
    public function store(Request $request)
    {
        $repository = new UsersRepository();

        return $repository->create($request->all());
    }
```

#### Methods

[](#methods)

This gives you access to methods such as...

creating a new query to get all results from repository:

```
// Definition:
$repository->all(array $columns = ['*']);
// Example:
$users = $repository->all(['name', 'value']);
```

\[Need fix\] creating a new basic where query clause on model and returns results:

```
// Definition:
$repository->where($column, $operator = '=', $value = null, $boolean = 'and', array $columns = ['*']);
// Example:
$repository->where('id', '', \Auth::user()->getKey(), 'and', ['activated', 'banned']);
```

creating a new query with pagination:

```
// Definition:
$repository->paginate($perPage = 15, array $columns = ['*']);
// Example:
$repository->paginate(50, ['name', 'value']);
```

saving a new model and return the instance:

```
// Definition:
$repository->create(array $attributes = []);
// Example:
$repository->create(['activated' => true, 'banned' => false]);
```

saving or updates the model in the database.

```
// Definition:
$repository->update($identifier, array $attributes = []);
// Example:
$repository->update(1, ['activated' => true, 'banned' => false]);
```

Also you can pass a model:

```
// Definition:
$repository->update($dirtyModel);
// Example:
$model = $repository->find(1);
$model->activated = true;
$repository->update($model);
```

even with additional attributes:

```
// Definition:
$repository->update($dirtyModel, ['activated' => true]);
// Example:
$model = $repository->find(1);
$model->activated = true;
$repository->update($model, ['banned' => false]);
```

delete the model from the database:

```
// Definition:
$repository->delete($identifier);
// Example:
$repository->delete(1);
```

find a model (only first result) by its primary key:

```
// Definition:
$repository->find($identifier, array $columns = ['*']);
// Example:
$repository->find(1, ['name', 'value']);
```

find a model (only first result) by its specified column and value:

```
// Definition:
$repository->findBy($column, $value, array $columns = ['*']);
// Example:
$repository->findBy('activated', true, ['id']);
```

find a model (only first result) by its specified columns and values presented as array:

```
// Definition:
$repository->findWhere(array $wheres, array $columns = ['*']);
// Example:
$repository->findWhere(['activated' => true, 'banned' => false], ['id']);
```

return total count of whole collection based on current query:

```
// Definition and example:
$repository->count();
```

fetch collection ordered and filtrated by specified columns for specified page and this method will return instance of `LengthAwarePaginator`:

```
// Definition:
$repository->fetch($page = 1, $perPage = 15, array $columns = ['*'], array $filter = [], array $sort = []);
// Example:
$repository->fetch(1, 15, ['*'], ['activated' => true, 'banned' => 'false'], ['id' => 'ASC']);
```

fetch simple collection without `LengthAwarePaginator`, but ordered and filtrated by specified columns for specified page:

```
// Definition:
$repository->simpleFetch($page = 1, $perPage = 15, array $columns = ['*'], array $filter = [], array $sort = []);
// Example:
$repository->simpleFetch(1, 15, ['*'], ['activated' => true, 'banned' => 'false'], ['id' => 'ASC']);
```

#### Eager loads

[](#eager-loads)

If your model has a relationship and you want to load it, you can do this with query results by calling the `with` method, for example:

```
// Definition:
$repository->with($relations);
// Examples:
$repository->with('roles')->all();
$repository->with('roles', 'permissions')->all();
$repository->with(['roles', 'permissions])->all();
```

#### Criteria

[](#criteria)

Sometimes you need to prepare repeatable query that displays, for example, only active and not banned users or the latest news from the week before - to do this you can use a criteria:

```
class ActivatedAndNotBanned extends \SebastianBerc\Repositories\Criteria
{
    public function execute(Builder $query)
    {
        return $query->where(['activated' => true])->andWhere(['banned' => false]);
    }
}
```

Now you can use your criteria with repository:

```
$repository->criteria(new ActivatedAndNotBanned())->all();
```

#### Transformers

[](#transformers)

The data from your repositories can be sent to different places, for example, it may be your site or the same data with the exclusion of several columns can be shared with Web API, you can achieve through class `Transfomer`:

```
class UsersForListing extends \SebastianBerc\Repositories\Transformer
{
    public function transform($item)
    {
    	$item->fullname = $item->firstName . ' ' . $item->lastName;
        $item->password = '*****';

        return $item;
    }
}
```

When you have your own `Transformer` you can apply it to repository:

```
$repository->setTransformer(UsersForListing::class)->all();
```

#### Cached repository results

[](#cached-repository-results)

To hold query results in a cache just add the implementation of the interface `ShouldCache` to your repository:

```
class MyRepository extends \SebastianBerc\Repositories\Repository implements \SebastianBerc\Repositories\Contracts\ShouldCache
{
    /**
     * Return fully qualified model class name.
     *
     * @return string
     */
    public function takeModel()
    {
        return MyModel::class;
    }
}
```

And its magic because from now everything will be cached :).

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian Berć](https://github.com/SebastianBerc)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance43

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 80.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~500 days

Recently: every ~270 days

Total

8

Last Release

447d ago

PHP version history (5 changes)v1.0.0PHP &gt;=5.5.9

v1.1.0PHP &gt;=7.2.0

v1.2.0PHP ^7.3 | ^8.0 | ^8.1 | ^8.2

v1.3.0PHP ^7.3 | ^8.0 | ^8.1 | ^8.2 | ^8.3

v1.4.0PHP ^7.3 | ^8.0 | ^8.1 | ^8.2 | ^8.3 | ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/724121?v=4)[coliving](/maintainers/coliving)[@coliving](https://github.com/coliving)

---

Top Contributors

[![SebastianBerc](https://avatars.githubusercontent.com/u/8415559?v=4)](https://github.com/SebastianBerc "SebastianBerc (111 commits)")[![dungnh](https://avatars.githubusercontent.com/u/1852709?v=4)](https://github.com/dungnh "dungnh (24 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![ngoctiennet](https://avatars.githubusercontent.com/u/181210354?v=4)](https://github.com/ngoctiennet "ngoctiennet (1 commits)")

---

Tags

leaguerepository

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/coliving-repositories/health.svg)

```
[![Health](https://phpackages.com/badges/coliving-repositories/health.svg)](https://phpackages.com/packages/coliving-repositories)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel/pennant

A simple, lightweight library for managing feature flags.

57711.1M53](/packages/laravel-pennant)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
