PHPackages                             madulinux/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. madulinux/repository-pattern

ActiveLaravel-package[Framework](/categories/framework)

madulinux/repository-pattern
============================

Repository Pattern for Laravel

1.0.1(1y ago)04MITPHPPHP ^8.2

Since Jan 26Pushed 1y ago1 watchersCompare

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

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

Laravel Repository Pattern
==========================

[](#laravel-repository-pattern)

A flexible and feature-rich implementation of the Repository Pattern for Laravel applications.

Features
--------

[](#features)

- 🚀 **CRUD Operations** - Basic create, read, update, and delete operations
- 💾 **Caching Support** - Automatic caching with customizable drivers and keys
- 🔄 **Event System** - Before/After events for all operations
- 🗑️ **Soft Deletes** - Built-in support for soft deletes
- 📦 **Bulk Operations** - Efficient handling of multiple records
- 💼 **Transactions** - Database transaction support
- 🔍 **Query Builder** - Chainable query methods
- 📄 **Pagination** - Built-in pagination support
- 🔎 **Search** - Simple and advanced search capabilities

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

[](#installation)

```
composer require madulinux/repository-pattern
```

Basic Usage
-----------

[](#basic-usage)

### Generate Repository

[](#generate-repository)

```
php artisan make:repository User
```

This will create:

- `app/Repositories/UserRepository.php`
- `app/Repositories/Interfaces/UserRepositoryInterface.php`

### Basic Operations

[](#basic-operations)

```
class UserRepository extends Repository implements UserRepositoryInterface
{
    public function __construct(User $model)
    {
        $this->model = $model;
    }
}

// Usage
$users = $repository->all();
$user = $repository->find(1);
$user = $repository->create(['name' => 'John']);
$repository->update(1, ['name' => 'Jane']);
$repository->delete(1);
```

### Caching

[](#caching)

```
// Enable/Disable cache
$repository->enableCache();
$repository->disableCache();

// Set cache time
$repository->setCacheTime(60); // 60 minutes

// Set cache tags (for Redis/Memcached)
$repository->setCacheTags(['users']);

// Custom cache key
$repository->setCacheKeyGenerator(function($method, $args, $model) {
    return "users:{$method}:" . md5(serialize($args));
});
```

### Events

[](#events)

```
$repository->on('creating', function($data) {
    // Before create
});

$repository->on('created', function($model) {
    // After create
});

// Available events:
// - creating/created
// - updating/updated
// - deleting/deleted
```

### Soft Deletes

[](#soft-deletes)

```
// Get with soft deleted records
$repository->withTrashed()->get();

// Get only soft deleted records
$repository->onlyTrashed()->get();

// Restore soft deleted records
$repository->restore($id);

// Force delete
$repository->forceDelete($id);
```

### Bulk Operations

[](#bulk-operations)

```
// Insert multiple
$repository->insert([
    ['name' => 'John'],
    ['name' => 'Jane']
]);

// Update multiple
$repository->bulkUpdate(
    ['status' => 'active'],
    ['department' => 'IT']
);

// Delete multiple
$repository->bulkDelete([1, 2, 3]);

// Upsert
$repository->upsert(
    [['id' => 1, 'name' => 'John']],
    'id',
    ['name']
);

// Chunk processing
$repository->chunk(100, function($users) {
    foreach($users as $user) {
        // Process each user
    }
});
```

### Transactions

[](#transactions)

```
// Using callback
$repository->transaction(function() use ($repository) {
    $user = $repository->create(['name' => 'John']);
    $profile = $repository->create(['user_id' => $user->id]);
});

// Manual control
$repository->beginTransaction();
try {
    $user = $repository->create(['name' => 'John']);
    $profile = $repository->create(['user_id' => $user->id]);
    $repository->commit();
} catch (\Exception $e) {
    $repository->rollBack();
    throw $e;
}
```

### Query Builder

[](#query-builder)

```
// Chainable methods
$repository
    ->with(['posts', 'comments'])
    ->filter(['status' => 'active'])
    ->orderBy('created_at', 'desc')
    ->paginate(15);

// Search
$users = $repository->search('john', ['name', 'email']);

// Advanced filtering
$users = $repository->getFiltered([
    'status' => 'active',
    'role' => ['admin', 'manager'],
    'age' => ['operator' => '>=', 'value' => 18]
], [
    'sort_by' => 'created_at',
    'sort_direction' => 'desc',
    'per_page' => 15
]);
```

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

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

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Author Name](https://github.com/username)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance44

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Total

2

Last Release

442d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/540a1079a75ed1f384b57a25fbeca234d0f7725c5bc019eeb764ce8745eb8cb7?d=identicon)[madulinux](/maintainers/madulinux)

---

Top Contributors

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

---

Tags

laravelrepository patternrepositorypatternlaravel-repository

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mahabub/laravel-crud-and-repository-generator

laravel crud generator with repository pattern

111.7k](/packages/mahabub-laravel-crud-and-repository-generator)

PHPackages © 2026

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