PHPackages                             nanvaie/database-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. [Database &amp; ORM](/categories/database)
4. /
5. nanvaie/database-repository

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

nanvaie/database-repository
===========================

Repository Pattern

v2.0.1(1y ago)199099[4 issues](https://github.com/iran-coders/database-repository/issues)MITPHPPHP ^8.1CI failing

Since Mar 2Pushed 1y ago2 watchersCompare

[ Source](https://github.com/iran-coders/database-repository)[ Packagist](https://packagist.org/packages/nanvaie/database-repository)[ RSS](/packages/nanvaie-database-repository/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (5)Versions (32)Used By (0)

Database Repository / PHP Repository / Laravel Repository
=========================================================

[](#database-repository--php-repository--laravel-repository)

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

[](#installation)

Use the following command to add this package to the composer development requirement.

```
composer require eghamat24/database-repository --dev
```

### Setup Laravel Repository

[](#setup-laravel-repository)

Then run the following command in the console to publish the necessary assets in your project directory.

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

### Setup Lumen Repository

[](#setup-lumen-repository)

Navigate to `app.php` in `bootstrap` folder and add the following line after service providers registrations:

```
// snip
if ($app->environment('local', 'testing')) {
    $app->register(Eghamat24\DatabaseRepository\DatabaseRepositoryServiceProvider::class);
}
// snip
```

Copy [repository.php](config/repository.php) to the project config folder located at the project root.

Note: Make sure to run `composer dump-autoload` after these changes.

Usage
-----

[](#usage)

To use this package easily, you can run the following command. It will create all the required components such as Entity, IRepository, Repository, MySqlRepository, RedisRepository, Resource, and Factory for the users table.

```
php artisan repository:make-all --table_names=users --strategy_name=QueryCacheStrategy
```

List of artisan commands:

CommandInputsOptionsDescription`repository:make-entity`table\_name-f, -d, -k, -gCreate new Entity`repository:make-enum`table\_name-f, -d, -gCreate new Enum`repository:make-factory`table\_name-f, -d, -gCreate new Factory`repository:make-resource`table\_name-f, -d, -k, -gCreate new Resource`repository:make-interface-repository`table\_name-f, -d, -k, -gCreate new Repository Interface`repository:make-repository`table\_name, selected\_db(optional)-f, -d, -k, -gCreate new Base Repository`repository:make-mysql-repository`table\_name-f, -d, -k, -gCreate new MySql Repository class`repository:make-redis-repository`table\_name-f, -d, -k, -gCreate new Redis Repository class`repository:make-all`--table\_names=table\_names(optional)
--selected\_db=database(optional)-a, -f, -d, -k, -gRun all of the above commands### Options Explanation

[](#options-explanation)

- `-f|--force`: Force commands to override existing files.
- `-d|--delete`: Delete already created files.
- `-k|--foreign-keys`: Try to detect foreign keys of a table.
- `-g|--add-to-git`: Add created files to the git repository.
- `-a|--all-tables`: Use all existing tables.
- `--table_names=`: Add table names, separate names with comma.
- `--selected_db=` : Use between `Mysql`,`Redis`, If it does not send, the value will return from `config/repository.php`
- `--strategy_name=` : add a trait to your Redis repository based on the strategy you choose

Example 1. Create a new Entity for a table named 'users'.

```
php artisan repository:make-entity users
```

Example 2. Create all necessary classes for two tables named 'users' and 'customers' with an enabled foreign key option.

```
php artisan repository:make-all --table_names=users,customers -k
```

Example 3. Create all necessary classes for all tables with an enabled foreign key option(this may be used for new projects).

```
php artisan repository:make-all -a -k
```

Cache Strategy
--------------

[](#cache-strategy)

We created some strategies for caching data, based on the number of records and change frequency

### SingleKeyCacheStrategy

[](#singlekeycachestrategy)

SingleKeyCacheStrategy is a good choice for tables with very few rows, such as less than 50 records. This strategy creates one cache key and stores all the data on it. Then, when the app queries data, it loops through the data and returns the result.

This strategy has one cache key and clears all the cached data whenever there is a change. This ensures that the data is always updated and valid.

### QueryCacheStrategy

[](#querycachestrategy)

QueryCacheStrategy is suitable for tables that have low change frequency and not too many records. For example, if the table has less than 10,000 rows or if it has more than that but the queries are not very unique and there are similar queries, this strategy works well.

This strategy assigns a tag to each cache of the repository and clears all the cached data whenever there is a change. This ensures that the data is always updated and valid.

### TemporaryCacheStrategy

[](#temporarycachestrategy)

TemporaryCacheStrategy is useful when we have a large or diverse amount of data and the data user can tolerate some delay in the updates. We cache every request and delay the changes that are not critical to be reflected in real time. For example, if we have a post and we edit its content, we can cache the old version until the cache expires. We set the cache expiration time for each data item based on the maximum delay the user can accept. This way, we use this strategy to cache data temporarily.

### ClearableTemporaryCacheStrategy

[](#clearabletemporarycachestrategy)

Sometimes, we need to clear the data from a temporary cache when some critical changes occur. ClearableTemporaryCacheStrategy is suitable for these situations.

```
php artisan repository:make-all --table_names=users --strategy_name=QueryCacheStrategy
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance41

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~36 days

Recently: every ~108 days

Total

31

Last Release

434d ago

Major Versions

0.x-dev → 1.0.12022-12-09

v1.3.5 → v2.0.02024-11-02

PHP version history (3 changes)v0.8PHP ^8.0

v0.8.3PHP ^7.0|^8.0

v1.3.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d141a9a1f1dfef4e9621581ae71fa321ade9d7d08ab894d77efa11298dd8915b?d=identicon)[nanvaie](/maintainers/nanvaie)

---

Top Contributors

[![MR-Sharifi](https://avatars.githubusercontent.com/u/29632708?v=4)](https://github.com/MR-Sharifi "MR-Sharifi (106 commits)")[![mbpcoder](https://avatars.githubusercontent.com/u/3877538?v=4)](https://github.com/mbpcoder "mbpcoder (48 commits)")[![saMahmoudzadeh](https://avatars.githubusercontent.com/u/36761585?v=4)](https://github.com/saMahmoudzadeh "saMahmoudzadeh (36 commits)")[![sama20](https://avatars.githubusercontent.com/u/12247542?v=4)](https://github.com/sama20 "sama20 (12 commits)")[![jbidad](https://avatars.githubusercontent.com/u/51882296?v=4)](https://github.com/jbidad "jbidad (10 commits)")[![farshadth](https://avatars.githubusercontent.com/u/19472129?v=4)](https://github.com/farshadth "farshadth (4 commits)")[![mohammadRezaei1380](https://avatars.githubusercontent.com/u/135225767?v=4)](https://github.com/mohammadRezaei1380 "mohammadRezaei1380 (3 commits)")[![mohsenetm](https://avatars.githubusercontent.com/u/56743266?v=4)](https://github.com/mohsenetm "mohsenetm (3 commits)")[![amirnajmieghamat](https://avatars.githubusercontent.com/u/115634417?v=4)](https://github.com/amirnajmieghamat "amirnajmieghamat (2 commits)")

---

Tags

laravellaravel-packagelaravel-repositorylaravel-repository-patternlumenphprepositoryrepository-pattern

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[ryangjchandler/orbit

A flat-file database driver for Eloquent.

922256.2k5](/packages/ryangjchandler-orbit)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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