PHPackages                             longaodai/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. [Framework](/categories/framework)
4. /
5. longaodai/repository-pattern

ActiveLibrary[Framework](/categories/framework)

longaodai/repository-pattern
============================

This is library support for project Laravel use repository design pattern

v1.0.2(2y ago)27MITPHPPHP &gt;=7.0

Since Mar 17Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (5)Used By (0)

LongAoDai Repository Pattern
============================

[](#longaodai-repository-pattern)

This package provides a base repository implementation following the repository design pattern in PHP.

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

[](#installation)

You can install this package via Composer. Run the following command in your terminal:

```
composer require longaodai/repository-pattern
```

In `config/app.php` add provider

```
'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        \LongAoDai\Repositories\RepositoryServiceProvider::class,
    ])->toArray(),
```

Public config file `pattern.php`

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

*Result exec 🍀:*

```
 Copying file [vendor/longaodai/repository-pattern/config/pattern.php] to [config/pattern.php] ............................................... DONE
```

😀 Now, you can the create repository by command instead of creating it manually .

```
php artisan setup:repository Comment
```

*Result exec 🍀:*

```
Repository Comment created successfully !!!
Implement: App\Repositories\CommentEloquentRepository.php
Interface: App\Repositories\CommentRepositoryInterface.php
```

After running the first repository creation command, in the `app/Providers` folder there will be auto create a `RepositoryServiceProvider.php` file. Pls add more into `config/app.php` for register custom provider.

```
'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        \LongAoDai\Repositories\RepositoryServiceProvider::class,
        \App\Providers\RepositoryServiceProvider::class,
    ])->toArray(),
```

Usage
-----

[](#usage)

To use the base repository in your project, you need to create repository classes that extend the BaseRepository class provided by this package.

Here's an example of how to create a repository class:

```
use LongAoDai\Repositories\BaseRepository;

class UserRepository extends BaseRepository
{
    /**
     * Specify the model class name.
     *
     * @return mixed
     */
    public function model()
    {
        return User::class;
    }
}

public function getList($data = null, $options = null): mixed
{
    $this->method('select', [
        'name', 'email'
    ]);

    return parent::getList($data, $options);
}

protected function filter($params): UserRepository
{
    if ($params->get('name')) {
        $this->method('where', 'name', 'like', '%' . $params->get('name') . '%');
    }

    if ($params->get('id')) {
        $this->method('where', 'id', $params->get('id'));
    }

    return parent::filter($params);
}

protected function mark($params): UserRepository
{
    if ($params->option('id')) {
        $this->method('where', 'id', $params->option('id'));
    }

    return parent::mark($params);
}
```

You can then use methods provided by the BaseRepository class such as all(), find(), create(), update(), and delete() in your repository classes.

In controller file you can use

```
public function index()
{
    $repository = app(UserRepository::class);
    // Get list with pagination
    $user = $repository->getList($data = null, $options = null);
    // Get all data
    $user = $repository->all($data = null, $options = null);
    // Find by id
    $user = $repository->find(['id' => 1]);
    // Update data
    $user = $repository->update(
        collect([
            'name' => 'Vo Chi Long'
        ]),
        collect(['id' => 1])
    );
    // Create data
    $user = $repository->create(collect([
        'name' => 'Vo Chi Long',
        'email' => 'vochilong.work@gmail.com',
        'password' => bcrypt('password'),
    ]));
    // Get first by params condition
    $user = $repository->first(collect([
        'name' => 'Long'
    ]));
    // Update or Create by options condition
    $user = $repository->updateOrCreate(collect([
        'name' => 'Vo Chi Long'
    ]), collect([
        'email' => 'vochilong.work@gmail.com'
    ]));
    // Delete data by condition
    $user = $repository->destroy(['id' => 10]);

    return json_encode($user ?? []);
}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

3

Last Release

778d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/64a3a64111fb9b445f9c547e72d472ba98622e805d64ce36e38382bc67b32f2d?d=identicon)[longaodai](/maintainers/longaodai)

---

Top Contributors

[![longaodai](https://avatars.githubusercontent.com/u/87090422?v=4)](https://github.com/longaodai "longaodai (11 commits)")

---

Tags

hioncodinglaravellaravel-packagelongaodailongkunphprepository-patternrepository-pattern-php

### Embed Badge

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

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M191](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M256](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M592](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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