PHPackages                             writeshh/yarp - 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. writeshh/yarp

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

writeshh/yarp
=============

Yet Another Repository Pattern, my take on Repository Design Pattern.

1.1.0(11mo ago)03MITPHPPHP &gt;=8.1

Since Jul 17Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/writeshh/yarp)[ Packagist](https://packagist.org/packages/writeshh/yarp)[ Docs](https://github.com/writeshh/yarp)[ RSS](/packages/writeshh-yarp/feed)WikiDiscussions main Synced today

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

YARP - Yet Another Repository Pattern
=====================================

[](#yarp---yet-another-repository-pattern)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1e088ac37dec0b61d44a36513487dcbe06b5532d63e1c62d21f7b21fe2a78cce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77726974657368682f796172702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/writeshh/yarp)[![Total Downloads](https://camo.githubusercontent.com/abed61ccb1d5f4a4751e5d4d428a289e3742aa966bc839d30cae9a5018ecf92a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77726974657368682f796172702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/writeshh/yarp)[![GitHub Actions](https://github.com/writeshh/yarp/actions/workflows/main.yml/badge.svg)](https://github.com/writeshh/yarp/actions/workflows/main.yml/badge.svg)

A simple yet powerful implementation of the Repository Pattern for Laravel. This package provides a quick way to generate repository classes for your Laravel models and standardize data access across your application.

YARP (Yet Another Repository Pattern) helps separate your data access layer from your business logic, making your code more maintainable, testable, and scalable. It automatically generates repository classes, binds them in a service provider, and follows Laravel best practices.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.0+

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

[](#installation)

You can install the package via composer:

```
composer require writeshh/yarp
```

The package will automatically register its service provider if you're using Laravel's package auto-discovery.

Usage
-----

[](#usage)

### Generating a Repository

[](#generating-a-repository)

You can generate a repository for your model using the Artisan command:

```
php artisan make:repo User
```

This will create a new repository class at `app/Repositories/UserRepository.php` that implements the standard repository interface.

### Using the Repository in Your Application

[](#using-the-repository-in-your-application)

The package also automatically creates a service provider binding for your repository. You'll need to register the generated `RepositoryServiceProvider` in your `config/app.php` providers array:

```
'providers' => [
    // Other providers...
    App\Providers\RepositoryServiceProvider::class,
],
```

Then, you can inject and use your repository in your controllers or services:

```
use App\Repositories\UserRepository;

class UserController extends Controller
{
    protected $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function index()
    {
        $users = $this->userRepository->all();
        return view('users.index', compact('users'));
    }

    public function show($id)
    {
        $user = $this->userRepository->show($id);
        return view('users.show', compact('user'));
    }

    public function store(Request $request)
    {
        $user = $this->userRepository->create($request->validated());
        return redirect()->route('users.show', $user->id);
    }
}
```

### Available Repository Types

[](#available-repository-types)

You can generate two types of repositories:

1. **Basic Repository** - Directly implements RepositoryInterface (default):

```
php artisan make:repo User
```

This approach gives you complete control over implementation details. Good for custom repository logic.

2. **Extended Repository** - Extends the BaseRepository class:

```
php artisan make:repo User --type=extended
```

This approach uses inheritance to reduce boilerplate code. The BaseRepository already implements all the standard methods, so you only need to add custom methods for your specific needs.

### Customizing Stubs

[](#customizing-stubs)

You can publish the stubs to customize them:

```
php artisan vendor:publish --tag=yarp-stubs
```

### Testing

[](#testing)

YARP comes with a comprehensive test suite. To run the tests:

```
composer test
```

For detailed guidance on testing your repositories and the package itself, see [TESTING.md](TESTING.md).

#### Quick Example

[](#quick-example)

Here's a simple example of testing a repository:

```
use Tests\TestCase;
use App\Models\User;
use App\Repositories\UserRepository;

class UserRepositoryTest extends TestCase
{
    protected UserRepository $repository;

    protected function setUp(): void
    {
        parent::setUp();
        $this->repository = new UserRepository(new User());
    }

    /** @test */
    public function it_can_create_a_user()
    {
        $user = $this->repository->create([
            'name' => 'John Doe',
            'email' => 'john@example.com',
            'password' => bcrypt('password')
        ]);

        $this->assertNotNull($user);
        $this->assertEquals('John Doe', $user->name);
        $this->assertDatabaseHas('users', ['email' => 'john@example.com']);
    }
}
```

### Changelog

[](#changelog)

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

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, create a new issue with the issue tracker.

Credits
-------

[](#credits)

- [Ritesh Shrestha](https://github.com/writeshh)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Why Use the Repository Pattern?
-------------------------------

[](#why-use-the-repository-pattern)

- **Separation of Concerns**: Isolate data access logic from business logic
- **Consistency**: Standardize data access across your application
- **Testability**: Easily mock repositories in your tests
- **Flexibility**: Switch underlying data sources without changing business logic
- **Maintainability**: Centralize data access code for better organization

Documentation
-------------

[](#documentation)

Full documentation can be found on the [GitHub wiki](https://github.com/writeshh/yarp/wiki).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance50

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Every ~0 days

Total

2

Last Release

351d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.0

1.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f519c0410686e683b6539ac9d58a2f1d4073a0f5b3808464b51adb9a65995ab?d=identicon)[writeshh](/maintainers/writeshh)

---

Top Contributors

[![writeshh](https://avatars.githubusercontent.com/u/26714639?v=4)](https://github.com/writeshh "writeshh (7 commits)")

---

Tags

servicerepositorydesignpatternwriteshhyarp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/writeshh-yarp/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[getsolaris/laravel-make-service

A MVCS pattern create a service command for Laravel 5+

81173.8k](/packages/getsolaris-laravel-make-service)

PHPackages © 2026

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