PHPackages                             thombas/revised-repository-pattern - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. thombas/revised-repository-pattern

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

thombas/revised-repository-pattern
==================================

A package that adds a repository pattern which extends from the established models.

v1.0.3(10mo ago)059MITPHPPHP ^8.0CI passing

Since Mar 30Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Thombas/revised-repository-pattern)[ Packagist](https://packagist.org/packages/thombas/revised-repository-pattern)[ RSS](/packages/thombas-revised-repository-pattern/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Revised Repository Pattern for Laravel
======================================

[](#revised-repository-pattern-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e89ad3993bb66e7d7455e9190b798038c6755e85ede497e04b2d3714a62dd0f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74686f6d6261732f726576697365642d7265706f7369746f72792d7061747465726e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thombas/revised-repository-pattern)[![Total Downloads](https://camo.githubusercontent.com/b7d3fb86ad1b47bc13498f35462260bc406457b18b9a1224a388fb4c7b6180b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74686f6d6261732f726576697365642d7265706f7369746f72792d7061747465726e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thombas/revised-repository-pattern)[![License: MIT](https://camo.githubusercontent.com/fe6ded080c51ae9f00860115f2f2df914b852870d1d983b2973e0753245d3afe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f54686f6d6261732f726576697365642d7265706f7369746f72792d7061747465726e3f7374796c653d666c61742d737175617265)](https://github.com/Thombas/revised-repository-pattern/blob/main/LICENSE)[![Tests](https://github.com/Thombas/revised-repository-pattern/actions/workflows/tests.yml/badge.svg)](https://github.com/Thombas/revised-repository-pattern)

---

Introduction
------------

[](#introduction)

The **Revised Repository Pattern** is a Laravel package designed to help you organize your model-related logic without sacrificing the native elegance of Laravel's Eloquent models.

This package is perfect if you want:

✅ Cleaner, more structured model actions and queries
✅ Singleton-based repository access
✅ Full compatibility with Laravel's native models

---

Features
--------

[](#features)

- Lightweight and non-intrusive
- Extends Laravel's Eloquent model system
- Clean repository interface via Singleton pattern
- Artisan commands for generating Actions &amp; Queries
- Supports standalone Actions &amp; Queries without model attachment

---

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

[](#installation)

```
composer require thombas/revised-repository-pattern
```

---

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

[](#getting-started)

### ✅ Step 1 — Add the Trait to Your Model

[](#-step-1--add-the-trait-to-your-model)

Add the trait to any model you want to use the repository pattern with:

```
use Thombas\RevisedRepositoryPattern\Traits\ImplementsRevisedRepositoryPattern;

class User extends Model
{
    use ImplementsRevisedRepositoryPattern;
}
```

> 💡 If you have a base model, you can add it there to apply to all models.

---

### ✅ Step 2 — Accessing the Repository

[](#-step-2--accessing-the-repository)

You can access the repository both statically and through an instance:

```
User::repository(); // Static
$user->repository(); // Instance
```

Or, for general actions/queries:

```
\Thombas\RevisedRepositoryPattern\Repository\Repository::action();
```

---

### ✅ Step 3 — Generate Actions &amp; Queries

[](#-step-3--generate-actions--queries)

By default, actions and queries will live under:

```
App\Actions
App\Queries

```

You can manually create these folders or use Artisan:

```
php artisan repository:action ActionName --model=User
php artisan repository:query QueryName --model=User
```

#### Optional:

[](#optional)

Generate into subdirectories:

```
php artisan repository:action ActionName --model=User --dir=Crud/Create
```

Resulting namespace:

```
App\Actions\Models\User\Crud\Create

```

---

### ✅ Step 4 — Writing an Action

[](#-step-4--writing-an-action)

Actions are simple classes where you define model-specific logic inside an `__invoke()` method:

```
public function __invoke(): mixed
{
    $this->model->create([
        'first_name' => 'Thomas',
        'last_name' => 'Fielding',
    ]);
}
```

#### Adding Parameters to an Action:

[](#adding-parameters-to-an-action)

```
public function __construct(
    public Model $model,
    public string $firstName,
    public string $lastName,
) {
    parent::__construct(model: $model);
}

public function __invoke(): mixed
{
    $this->model->create([
        'first_name' => $this->firstName,
        'last_name'  => $this->lastName,
    ]);
}
```

> ℹ️ Always call `parent::__construct()` when using the constructor.

#### Calling an Action with Parameters:

[](#calling-an-action-with-parameters)

```
$user->repository()->action()->createAndEmail(
    firstName: 'Thomas',
    lastName: 'Fielding'
);
```

---

### ✅ Step 5 — Writing a Query

[](#-step-5--writing-a-query)

Queries let you encapsulate common SQL logic:

```
public function __invoke(): EloquentBuilder|QueryBuilder
{
    return $this->model
        ->query()
        ->where('first_name', 'Thomas');
}
```

#### Query with Parameters:

[](#query-with-parameters)

```
public function __construct(
    public Model $model,
    public string $firstName,
    public string $lastName,
) {
    parent::__construct(model: $model);
}

public function __invoke(): mixed
{
    return $this->model
        ->query()
        ->where('first_name', $this->firstName)
        ->where('last_name', $this->lastName);
}
```

---

### ✅ Model-Detached Query Example:

[](#-model-detached-query-example)

If your query doesn't need a model:

```
public function __construct(
    public string $firstName,
    public string $lastName,
) {
    parent::__construct(model: null);
}

public function __invoke(): mixed
{
    return User::query()
        ->where('first_name', $this->firstName)
        ->where('last_name', $this->lastName);
}
```

> ⚠️ Requires extending the `BaseQuery` class instead of `ModelQuery`.

---

### ✅ Calling a Query with Parameters:

[](#-calling-a-query-with-parameters)

```
$user->repository()->query()->name(
    firstName: 'Thomas',
    lastName: 'Fielding'
);
```

---

🟣 Full Example
--------------

[](#-full-example)

```
User::repository()->action()->doSomethingCustom();
```

---

📜 Changelog
-----------

[](#-changelog)

See the [CHANGELOG](https://github.com/Thombas/revised-repository-pattern/blob/main/CHANGELOG.md) for updates.

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome!
See [CONTRIBUTING.md](https://github.com/Thombas/revised-repository-pattern/blob/main/.github/CONTRIBUTING.md) for guidelines.

---

🔒 Security
----------

[](#-security)

If you find a security vulnerability, please check our [Security Policy](https://github.com/Thombas/revised-repository-pattern/security/policy).

---

🏆 Credits
---------

[](#-credits)

- [Thomas Fielding](https://github.com/Thombas)

---

License
-------

[](#license)

This package is open-sourced software licensed under the **MIT License**.
See the [LICENSE file](https://github.com/Thombas/revised-repository-pattern/blob/main/LICENSE.md) for full details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance55

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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

Total

3

Last Release

304d ago

### Community

Maintainers

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

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/thombas-revised-repository-pattern/health.svg)

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

###  Alternatives

[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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