PHPackages                             mrtolouei/laravel-repo-mate - 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. mrtolouei/laravel-repo-mate

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

mrtolouei/laravel-repo-mate
===========================

A clean and flexible base repository package for Laravel that simplifies data access, enforces the repository pattern, and keeps your code organized and testable.

v1.0.0(8mo ago)03MITPHPPHP &gt;=8.0CI passing

Since Aug 23Pushed 8mo agoCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Laravel RepoMate
================

[](#laravel-repomate)

**A modern, flexible, and filterable Eloquent repository base for Laravel.**

Laravel RepoMate simplifies your data access layer by providing a reusable, testable, and maintainable repository structure. It includes filtering, chainable queries, pagination, CRUD operations, soft deletes, and batch inserts—all with Laravel Eloquent.

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Tests](https://github.com/mrtolouei/laravel-repo-mate/actions/workflows/tests.yml/badge.svg)](https://github.com/mrtolouei/laravel-repo-mate/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/b7a23d9ca395a19512815c441892bc7331e2c2a74f2513d6c65da6fdad959502/68747470733a2f2f706f7365722e707567782e6f72672f6d72746f6c6f7565692f6c61726176656c2d7265706f2d6d6174652f762f737461626c65)](https://packagist.org/packages/mrtolouei/laravel-repo-mate)

---

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

[](#table-of-contents)

1. [Installation](#installation)
2. [Creating a Repository](#creating-a-repository)
3. [Filterable Trait](#filterable-trait)
4. [Using Filters](#using-filters)
5. [Basic Query Methods](#basic-query-methods)
6. [Chainable Queries](#chainable-queries)
7. [Custom Queries](#custom-queries)
8. [Persisting Queries](#persisting-queries)
9. [CRUD Operations](#crud-operations)
10. [Advance Usages](#advanced-usage)
11. [Testing](#testing)
12. [Contributing](#contributing)
13. [License](#license)

---

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

[](#installation)

Install via composer:

```
composer require mrtolouei/laravel-repo-mate
```

---

Creating a Repository
---------------------

[](#creating-a-repository)

To create a new repository, extend BaseRepository and pass the model in the constructor:

```
use App\Models\User;
use RepoKit\Repositories\BaseRepository;

class UserRepository extends BaseRepository
{
    public function __construct(User $model)
    {
        parent::__construct($model);
    }
}
```

---

Filterable Trait
----------------

[](#filterable-trait)

To create a new repository, extend BaseRepository and pass the model in the constructor:

Key properties:

- `$activeFilters`: Parameters set at runtime.
- `$filterDefinitions`: Define how filters are applied (column, type, operator, relation).
- `$filtersApplied`: Internal flag to prevent applying filters multiple times.

Filter definition structure:

```
[
    'filter_name' => [
        'column'   => 'db_column',     // DB column name
        'type'     => 'string|integer|boolean|array|datetime', // Type of filter
        'operator' => '=',             // Optional, defaults to '='
        'relation' => 'relationName',  // Optional, for whereHas
    ]
]
```

---

Using Filters
-------------

[](#using-filters)

Filters are defined in your repository as an array:

```
use App\Models\User;
use RepoKit\Repositories\BaseRepository;

class UserRepository extends BaseRepository
{
    protected array $filterDefinitions = [
        'email' => [
            'column' => 'email',
            'type'   => 'string'
        ],
        'roles' => [
            'column' => 'id',
            'type' => 'array',
            'operator' => '=',
            'resource' => 'roles' //Relation name in User model
        ],
        'age' => [
            'column' => 'age',
            'type' => 'integer',
            'operator' => '>='
        ],
        'is_active' => [
            'column' => 'is_active',
            'type' => 'boolean',
        ]
    ];
}
```

You can apply filters dynamically at runtime using the repository’s `setFilter()` method. This is especially useful in a controller, where you can use query parameters from the HTTP request:

```
public function index(Request $request)
{
    $userRepo = new UserRepository(new User());

    // Apply filters from query parameters
    $users = $userRepo->setFilter($request->query())->all();

    return response()->json($users);
}
```

Explanation:

- `setFilter()` accepts an array of filter parameters (e.g., from `request()->query()`).
- The repository automatically applies the filters according to the `filterDefinitions` you defined in your repository.
- This approach keeps your controller clean and leverages the repository’s built-in filtering system.

---

Basic Query Methods
-------------------

[](#basic-query-methods)

MethodDescriptionExample`query(): Builder`Get the query builder instance for customization`$query = $userRepo->query();``where(...)`Add a `where` clause`$userRepo->where('is_active', true)->all();``with([...])`Eager load relations`$userRepo->with(['posts', 'profile'])->all();``orderBy(...)`Order results`$userRepo->orderBy('created_at', 'desc')->all();``limit(int)`Limit results`$userRepo->limit(10)->all();`---

Chainable Queries
-----------------

[](#chainable-queries)

All query-building methods return `$this` for chaining:

```
$users = $userRepo
    ->where('is_active', true)
    ->orderBy('created_at', 'desc')
    ->limit(5)
    ->all();
```

---

Custom Queries
--------------

[](#custom-queries)

Get the underlying query builder for advanced queries:

```
$query = $userRepo->query();

$query->where('role_id', 2)
      ->orWhere('is_active', false)
      ->get();
```

---

Persisting Queries
------------------

[](#persisting-queries)

Use `persistQuery()` to reuse the same query for multiple operations:

```
$query = $userRepo->persistQuery()
    ->where('role_id', 2)
    ->orderBy('created_at');

$firstUser = $query->first();
$allUsers = $query->all();
```

Without `persistQuery()`, queries are reset after each operation.

---

CRUD Operations
---------------

[](#crud-operations)

```
// Create
$newUser = $userRepo->create([
    'name' => 'Ali',
    'email' => 'ali@example.com',
]);

// Update
$updatedUser = $userRepo->update($newUser->id, ['name' => 'Ali Tolouei']);

// Delete
$deletedCount = $userRepo->delete($newUser->id);

// Restore
$restoredCount = $userRepo->restore($newUser->id);

// Bulk insert
$userRepo->insert([
    ['name' => 'User1', 'email' => 'u1@example.com'],
    ['name' => 'User2', 'email' => 'u2@example.com'],
]);
```

---

Advanced Usage
--------------

[](#advanced-usage)

```
$users = $userRepo
    ->setFilter(['role' => 2])
    ->where('is_active', true)
    ->orderBy('created_at', 'desc')
    ->with(['profile', 'posts'])
    ->paginate(10);
```

- Combines filters, chainable queries, and pagination.
- Supports eager loading relations.

---

Testing
-------

[](#testing)

```
composer test
```

---

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

[](#contributing)

1. Fork the repository
2. Create a feature branch (`feature/awesome-feature`)
3. Commit your changes (`git commit -m 'Add new feature'`)
4. Push to the branch (`git push origin feature/awesome-feature`)
5. Open a Pull Request

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance59

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

262d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/736fa5617032c5dbfb470d46a5f5c363dc4de7c368b36fae53d17e935df5adc3?d=identicon)[mrtolouei](/maintainers/mrtolouei)

---

Top Contributors

[![mrtolouei](https://avatars.githubusercontent.com/u/70100016?v=4)](https://github.com/mrtolouei "mrtolouei (3 commits)")

---

Tags

laravellaravel-packagelaravel-repositorylaravel-repository-patternphp-packagephp-repositoryrepository-pattern

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mrtolouei-laravel-repo-mate/health.svg)

```
[![Health](https://phpackages.com/badges/mrtolouei-laravel-repo-mate/health.svg)](https://phpackages.com/packages/mrtolouei-laravel-repo-mate)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

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

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)

PHPackages © 2026

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