PHPackages                             laravelutilities/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. [Caching](/categories/caching)
4. /
5. laravelutilities/repository

ActiveLibrary[Caching](/categories/caching)

laravelutilities/repository
===========================

Add-on on Laravel Models with caching implementation

v3.1.0(2y ago)16.3k↓33.3%MITPHP

Since Jan 26Pushed 2y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (11)Used By (0)

Model Repository package for Laravel
====================================

[](#model-repository-package-for-laravel)

This package allows you to create Model Repository with ease. You can use this package as an add-on on existing laravel model classes. Hightlights are given below

- Cache Repository
- Model Repository
- Make Repository Artisan Commands

Getting Started
---------------

[](#getting-started)

### 1. Install

[](#1-install)

Run the following command:

```
composer require laravelutilities/repository
```

### 2. Publish

[](#2-publish)

Publish config file.

```
php artisan vendor:publish --tag=repository
```

### 4. Configure

[](#4-configure)

You can change the options of your app from `config/repository.php` file

Usage
-----

[](#usage)

You can inject the dependency of a repository in any controller and use its functions like `$this->repository->fetchByCreatedAt('foo')` or if you want to use cache `$this->repository->fetchByCreatedAt('foo', 'cache')`

### Variations

[](#variations)

```
$this->repository->findByFieldFromCache('created_at', 'somevalue'); // extending cache repository; fetch only single value
$this->repository->findByFieldsFromCache(['created_at' => 'somevalue', 'city' => 'someanothervalue',...]); // fetch multiple values
$this->repository->findByField('created_at', 'somevalue'); // extending model repository; fetch only single value
$this->repository->findByField('created_at', 'somevalue'); // extending model repository; fetch only single value

public function fetchByFieldFromCache($key, $value);
public function fetchByFieldsFromCache(array $fieldsAndValues);

public function getById($id);
public function getByIds(array $ids)
```

### Controller Constructor

[](#controller-constructor)

```
use App\Repositories\OrganizationRepository;

protected $organization;

public function __construct()
{
    $this->organization = new OrganizationRepository();
}
```

### Repository Class with Database

[](#repository-class-with-database)

```
namespace App\Repositories;

use App\Models\AppLog;
use LaravelUtility\Repository\Repositories\ModelRepository;

class AppLogRepository extends ModelRepository
{
    public function __construct()
    {
        parent::__construct(new AppLog());
    }
}
```

### Repository Class with Cache

[](#repository-class-with-cache)

```
namespace App\Repositories;

use App\Models\AppLog;
use LaravelUtility\Repository\Repositories\CacheRepository;

class AppLogRepository extends CacheRepository
{
    public function __construct()
    {
        parent::__construct(new AppLog());
    }
}
```

### Model Repository Methods

[](#model-repository-methods)

```
public function findByField($key, $value);
public function findByFields(array $fieldsAndValues);

public function fetchByField($key, $value);
public function fetchByFields(array $fieldsAndValues);
```

### Cache Repository Methods

[](#cache-repository-methods)

```
public function findByFieldFromCache($key, $value);
public function findByFieldsFromCache(array $fieldsAndValues);

public function fetchByFieldFromCache($key, $value);
public function fetchByFieldsFromCache(array $fieldsAndValues);

public function getById($id);
public function getByIds(array $ids)
```

### Accessor Trait

[](#accessor-trait)

A Trait has been added to further augment these functions using magic method. In all the above mentioned functions, `Field` can be replaced in any of the model field. Suppose, you have a field `created_at` inside your table; this can be called in variaous ways given below

```
$this->repository->findByCreatedAt('somevalue'); // extending model repository; fetch only single value

$this->repository->findByCreatedAt('somevalue','cache'); // extending cache repository; fetch only single value

$this->repository->fetchByCreatedAt(['created_at' => 'somevalue', 'city' => 'someanothervalue',...]); // fetch multiple values
```

### Make Repository Command

[](#make-repository-command)

```
php artisan make:repository  --model= --cache=true/false
```

You can create Repository classes using `make:repository` command.

#### `` is mandatory; specifies the name of the repository. Using `Repository` as a suffix is mandatory. And if you don't write the name with `Repository` as suffix, command do for you.

[](#name-is-mandatory-specifies-the-name-of-the-repository-using-repository-as-a-suffix-is-mandatory-and-if-you-dont-write-the-name-with-repository-as-suffix-command-do-for-you)

#### `--model=modelname` as option if you don't menthion the name of the model, it tries to find the model same as Repository .if model is not created it ask if you want to creat new model.

[](#--modelmodelname-as-option-if-you-dont-menthion-the-name-of-the-model-it-tries-to-find-the-model-same-as-repository-if-model-is-not-created-it-ask-if-you-want-to-creat-new-model)

#### `cache=true|false`, default is true, your repository extends CacheRepository else Model Repository

[](#cachetruefalse-default-is-true-your-repository-extends-cacherepository-else-model-repository)

Changelog
---------

[](#changelog)

Please see [Releases](../../releases) for more information what has changed recently.

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 70% 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 ~209 days

Recently: every ~470 days

Total

10

Last Release

780d ago

Major Versions

v1.2.1 → v2.0.02019-01-28

v2.1.0 → v3.0.02024-03-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/43fe24e446da31ae0300c053bf49131a2f42916ffa4d4354a5379200fbc74114?d=identicon)[ankitfromindia](/maintainers/ankitfromindia)

---

Top Contributors

[![ankitatjunglee](https://avatars.githubusercontent.com/u/221352698?v=4)](https://github.com/ankitatjunglee "ankitatjunglee (7 commits)")[![ankitfromindia](https://avatars.githubusercontent.com/u/5277567?v=4)](https://github.com/ankitfromindia "ankitfromindia (3 commits)")

### Embed Badge

![Health badge](/badges/laravelutilities-repository/health.svg)

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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