PHPackages                             arifurrahmansw/laravel-repository - 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. arifurrahmansw/laravel-repository

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

arifurrahmansw/laravel-repository
=================================

A Laravel package that provides a reusable and extendable repository pattern implementation.

v1.2.3(10mo ago)345MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4

Since Aug 26Pushed 10mo agoCompare

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

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

🧰 Laravel Repository Generator
==============================

[](#-laravel-repository-generator)

A Laravel package that provides a clean, reusable, and extendable **Repository Pattern** implementation with artisan command support. Designed to keep your business logic separate from data access.

[![Packagist Stars](https://camo.githubusercontent.com/a165a238517b89652f2072d994f7bfb72626cca1394fd082d01d996577dafe1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6172696675727261686d616e73772f6c61726176656c2d7265706f7369746f7279)](https://packagist.org/packages/arifurrahmansw/laravel-repository)[ ![GitHub issues](https://camo.githubusercontent.com/43b0805c5222403e40aff97d8847235609b37cadb159328b188c8dafe1538b2c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6172696675727261686d616e73772f6c61726176656c2d7265706f7369746f7279)](https://packagist.org/packages/arifurrahmansw/laravel-repository)[![Total Downloads](https://camo.githubusercontent.com/b731f70b8ef4040530a31e9ce45b2d39b53e35b98b68e2c006ab0c3b5057545f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6172696675727261686d616e73772f6c61726176656c2d7265706f7369746f7279)](https://packagist.org/packages/arifurrahmansw/laravel-repository)[![Latest Stable Version](https://camo.githubusercontent.com/7396844acfac9a159928e180c1e083d502d57f04b17ce750195f16693e4ad6bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172696675727261686d616e73772f6c61726176656c2d7265706f7369746f7279)](https://packagist.org/packages/arifurrahmansw/laravel-repository)[![License](https://camo.githubusercontent.com/e012692c97d2a775de086b80a47f7a6ef04d937b0ae4422aaa562f6d466a01aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6172696675727261686d616e73772f6c61726176656c2d7265706f7369746f7279)](https://packagist.org/packages/arifurrahmansw/laravel-repository)

--- 📦 Package Name
--------------

[](#-package-name)

**`arifurrahmansw/laravel-repository`**

> Build maintainable Laravel apps using the repository pattern with ease.

---

🚀 Features
----------

[](#-features)

- 🧠 Simple command to generate repository pattern files
- 📁 Automatically generates:
    - Repository Interface
    - Repository Class (extends `BaseRepository`)
    - Optional Eloquent Model
- 🔌 Auto-binds interface to implementation in your `RepositoryServiceProvider`
- ⚙️ Customizable stub publishing
- 🧪 Compatible with Laravel 10, 11, 12+

---

📥 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require arifurrahmansw/laravel-repository
```

Publish the package assets (provider, stubs, etc.):

```
php artisan vendor:publish --tag=laravel-repository-provider
```

---

🔧 Configuration
---------------

[](#-configuration)

This package supports Laravel's auto-discovery out of the box.

If you want to register the service provider manually, add it to your `config/app.php` providers array:

```
'providers' => [
    // Other service providers...

    App\Providers\RepositoryServiceProvider::class,
],
```

---

✨ Usage
-------

[](#-usage)

📁 Generate a Repository

To generate a full repository structure for a model:

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

This will:

✅ Create `App\Models\User` (if it doesn’t exist)

✅ Generate `UserInterface.php` and `UserAbstract.php` under `App\Repositories\User`

✅ Register binding automatically inside `App\Providers\RepositoryServiceProvider`

🔀 Generate Repository Without Model

```
php artisan make:repo User --no-model
```

🗂 Directory Structure (Generated)

```
app/
├── Models/
│   └── User.php
├── Http/
│   └── Controllers/
│       └── UserController.php
├── Repositories/
│   └── User/
│       ├── UserInterface.php
│       └── UserAbstract.php
└── Providers/
    └── RepositoryServiceProvider.php

```

🔁 Interface Binding

The package auto-registers this in your `RepositoryServiceProvider`:

```
$this->app->bind(
    \App\Repositories\User\UserInterface::class,
    \App\Repositories\User\UserAbstract::class
);
```

All generated repositories extend `ArifurRahmanSw\Repository\BaseRepository`.

✨ Available Methods

```
public function paginate(int $limit = 10): LengthAwarePaginator;
public function all(): Collection;
public function combo(string $key = 'id', string $value = 'name'): Collection;
public function find(int $id): ?Model;
public function findBy(string $field, $value): ?Model;
public function store(array $data): object;
public function update(int $id, array $data): object;
public function destroy(int $id): object;
public function statusUpdate(int $id): object;
public function search(array $filters = [], int $limit = 10): LengthAwarePaginator;
public function restore(int $id): object;
```

🛠 Helper Response Methods
-------------------------

[](#-helper-response-methods)

```
formatResponse(bool $status, string $message, string $redirect_to, $data = null);
successResponse(int $code, string $message, $data = null);
jsonResponse(string $message = null, array|object $data = [], int $statusCode = 200);
```

🧪 Example Usage in Controller
-----------------------------

[](#-example-usage-in-controller)

```
use App\Repositories\User\UserInterface;

class UserController extends Controller
{
      /**
     * The repository instance.
     *
     * @var UserInterface
     */
    protected UserInterface $user;

    public function __construct(UserInterface $user)
    {
        $this->user = $user;
    }

    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $data = $this->user->paginate(10);
        return view('users.index', compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        return view('users.create');
    }

    /**
     * Store a newly created resource.
     */
    public function store(StoreUserRequest $request)
    {
        $result = $this->user->store($request->validated());

        if ($result->status) {
            return redirect()->route($result->redirect_to)->with('success', $result->message);
        }

        return back()->with('danger', $result->message);
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(int $id)
    {
        $data = $this->user->find($id);
        return view('users.edit', compact('data'));
    }

    /**
     * Update the specified resource.
     */
    public function update(UpdateUserRequest $request, int $id)
    {
        $result = $this->user->update($id, $request->validated());

        if ($result->status) {
            return redirect()->route($result->redirect_to)->with('success', $result->message);
        }

        return back()->with('danger', $result->message);
    }

    /**
     * Remove the specified resource.
     */
    public function destroy(int $id)
    {
        $result = $this->user->destroy($id);

        if ($result->status) {
            return redirect()->route($result->redirect_to)->with('success', $result->message);
        }

        return back()->with('danger', $result->message);
    }

    /**
     * Toggle status of the resource.
     */
    public function statusUpdate(int $id)
    {
        $result = $this->user->statusUpdate($id);

        if ($result->status) {
            return redirect()->route($result->redirect_to ?? 'users.index')
                ->with('success', $result->message);
        }

        return back()->with('danger', $result->message);
    }

    /**
     * Search resource by filters.
     */
    public function search(array $filters = [], int $limit = 10): LengthAwarePaginator
    {
        return $this->user->search($filters, $limit);
    }

    /**
     * Restore a soft-deleted resource.
     */
    public function restore(int $id)
    {
        $result = $this->user->restore($id);

        if ($result->status) {
            return redirect()->route($result->redirect_to)->with('success', $result->message);
        }

        return back()->with('danger', $result->message);
    }
}
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Contributions are welcome! Please feel free to open issues or submit pull requests. Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [arifurrahmansw](https://github.com/arifurrahmansw)

License
-------

[](#license)

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

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance54

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

Total

6

Last Release

313d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelpackagerepositoryrepository-patternlaravelrepository patternrepository

### Embed Badge

![Health badge](/badges/arifurrahmansw-laravel-repository/health.svg)

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

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

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