PHPackages                             sazl/laravel-repokit - 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. sazl/laravel-repokit

ActiveLibrary[Framework](/categories/framework)

sazl/laravel-repokit
====================

Repository Pattern implementation for Laravel

v2.0.0(1mo ago)113MITPHPPHP ^8.1CI passing

Since May 2Pushed 1mo agoCompare

[ Source](https://github.com/AffanAbd97/laravel-repokit)[ Packagist](https://packagist.org/packages/sazl/laravel-repokit)[ RSS](/packages/sazl-laravel-repokit/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (4)Used By (0)

Laravel RepoKit
===============

[](#laravel-repokit)

> Clean architecture scaffolding for Laravel (Repository + Service layers)

[![PHP](https://camo.githubusercontent.com/6351c44c5acd541a16e8505d9389a2576fb01528ebdbaf6a6b744ac49e401cae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312b2d626c7565)](https://camo.githubusercontent.com/6351c44c5acd541a16e8505d9389a2576fb01528ebdbaf6a6b744ac49e401cae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312b2d626c7565)[![Laravel](https://camo.githubusercontent.com/93554d1ac44e7880097a6bd117e99f90c33ddf03dcf0a37f3047fa50b8aaa4d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422d726564)](https://camo.githubusercontent.com/93554d1ac44e7880097a6bd117e99f90c33ddf03dcf0a37f3047fa50b8aaa4d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422d726564)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)

A Laravel package to scaffold Repository and Service layers, helping enforce clean architecture, improve maintainability, and reduce boilerplate in backend applications.

---

Why?
----

[](#why)

In many Laravel projects, business logic and data access are tightly coupled, making the code harder to maintain, scale, and test.

Laravel RepoKit helps you:

- Separate concerns using the Repository and Service patterns
- Maintain a clean and scalable architecture
- Reduce repetitive boilerplate code
- Speed up development with automated scaffolding

This also helps you standardize your application structure across teams and projects.

---

Key Features
------------

[](#key-features)

- Repository &amp; Service scaffolding
- Query Builder and Eloquent support
- Automatic interface binding
- Clean architecture enforcement
- Consistent project structure

---

Architecture Overview
---------------------

[](#architecture-overview)

Controller → Service → Repository → Database

- **Controller** handles HTTP requests
- **Service** contains business logic
- **Repository** handles data access

---

Auto-Binding
------------

[](#auto-binding)

All generated interfaces are automatically bound to their implementations in `AppServiceProvider`.

No manual dependency injection setup is required.

---

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

[](#requirements)

- PHP ^8.1
- Laravel 10.x, 11.x, or 12.x

---

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

[](#installation)

Install the package via Composer:

```
composer require sazl/laravel-repokit
```

The service providers will be auto-discovered by Laravel.

---

Usage
-----

[](#usage)

### Repositories

[](#repositories)

#### Basic Repository (Query Builder)

[](#basic-repository-query-builder)

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

This creates:

- `app/Repositories/Contracts/UserRepositoryInterface.php`
- `app/Repositories/Databases/UserRepository.php`

The generated repository uses Laravel's Query Builder (`DB` facade) with a raw query builder approach.

#### Repository with Eloquent Model

[](#repository-with-eloquent-model)

```
php artisan make:repository User --model=User
```

Generates the same structure, but uses Eloquent model injection instead of Query Builder. The model is resolved as `App\Models\User` unless a fully-qualified class name is provided.

---

### Services

[](#services)

#### Service with Repository Injection

[](#service-with-repository-injection)

```
php artisan make:service User
```

This creates:

- `app/Services/Contracts/UserServiceInterface.php`
- `app/Services/UserService.php`

By default the service is wired to the repository that matches the service name (`UserRepositoryInterface`). Use `--repository` to point to a different one:

```
php artisan make:service Order --repository=User
```

#### Empty Service (no pre-built methods)

[](#empty-service-no-pre-built-methods)

```
php artisan make:service User --empty
```

or the short flag:

```
php artisan make:service User -e
```

Generates the same file structure but with an empty interface and a minimal service class, useful when you want to define your own contract from scratch.

---

Generated File Structure
------------------------

[](#generated-file-structure)

```
app/
├── Repositories/
│   ├── Contracts/
│   │   └── {Name}RepositoryInterface.php
│   └── Databases/
│       └── {Name}Repository.php
└── Services/
    ├── Contracts/
    │   └── {Name}ServiceInterface.php
    └── {Name}Service.php

```

---

Example Output
--------------

[](#example-output)

### Repository (Query Builder)

[](#repository-query-builder)

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

**Interface** (`app/Repositories/Contracts/UserRepositoryInterface.php`):

```
interface UserRepositoryInterface
{
    public function all();
    public function find($id);
    public function create(array $data);
    public function update($id, array $data);
    public function delete($id);
}
```

**Implementation** (`app/Repositories/Databases/UserRepository.php`):

```
class UserRepository implements UserRepositoryInterface
{
    protected $connection = 'mysql';
    protected $table = 'users';

    protected function query()
    {
        return DB::connection($this->connection)->table($this->table);
    }

    public function all() { return $this->query()->get(); }
    public function find($id) { return $this->query()->where('id', $id)->first(); }
    public function create(array $data) { return $this->query()->insertGetId($data); }
    public function update($id, array $data) { return $this->query()->where('id', $id)->update($data); }
    public function delete($id) { return $this->query()->where('id', $id)->delete(); }
}
```

---

### Repository (Eloquent Model)

[](#repository-eloquent-model)

```
php artisan make:repository User --model=User
```

**Implementation** (`app/Repositories/Databases/UserRepository.php`):

```
class UserRepository implements UserRepositoryInterface
{
    public function __construct(protected User $model) {}

    public function all() { return $this->model->all(); }
    public function find($id) { return $this->model->find($id); }
    public function create(array $data) { return $this->model->create($data); }
    public function update($id, array $data) { ... }
    public function delete($id) { ... }
}
```

---

### Service

[](#service)

```
php artisan make:service User
```

**Interface** (`app/Services/Contracts/UserServiceInterface.php`):

```
interface UserServiceInterface
{
    public function getAll();
    public function getById($id);
    public function create(array $data);
    public function update($id, array $data);
    public function delete($id);
}
```

**Implementation** (`app/Services/UserService.php`):

```
class UserService implements UserServiceInterface
{
    public function __construct(
        protected UserRepositoryInterface $repository
    ) {}

    public function getAll() { return $this->repository->all(); }
    public function getById($id) { return $this->repository->find($id); }
    public function create(array $data) { return $this->repository->create($data); }
    public function update($id, array $data) { return $this->repository->update($id, $data); }
    public function delete($id) { return $this->repository->delete($id); }
}
```

---

Command Reference
-----------------

[](#command-reference)

CommandOptionsDescription`make:repository {name}``--model` / `-M`Generate a repository. Optionally inject an Eloquent model.`make:service {name}``--repository` / `-R`, `--empty` / `-e`Generate a service. Optionally target a specific repository or generate an empty scaffold.---

Use Case
--------

[](#use-case)

This package is ideal for:

- Medium to large-scale Laravel applications
- Teams enforcing clean architecture practices
- Developers who want consistent repository and service structure
- Projects requiring better separation of concerns

---

Background
----------

[](#background)

This package is inspired by real-world backend development, where maintaining a clear separation between business logic and data access is essential for long-term scalability and maintainability.

---

Clone and Test Locally
----------------------

[](#clone-and-test-locally)

### 1. Clone the Repository

[](#1-clone-the-repository)

```
git clone https://github.com/sazl/laravel-repokit.git
cd laravel-repokit
```

### 2. Install Dependencies

[](#2-install-dependencies)

```
composer install
```

### 3. Run Tests

[](#3-run-tests)

This package uses Orchestra Testbench:

```
./vendor/bin/phpunit
```

---

### 4. Test in a Laravel Project (Local Development)

[](#4-test-in-a-laravel-project-local-development)

To use this package in a local Laravel project without publishing to Packagist or pushing to Git, add a path repository to your Laravel app's `composer.json`:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "../laravel-repokit"
        }
    ]
}
```

> The `url` is relative to your Laravel app's root. Adjust it to match where you cloned this package.

Then require it using the `@dev` stability flag (since the package has no version tag defined):

```
composer require sazl/laravel-repokit:@dev
```

Composer will symlink the package directly into your `vendor` folder, so any changes you make to the package are reflected immediately — no reinstall needed.

Laravel will auto-discover the service providers via the `extra.laravel.providers` entry in `composer.json`.

---

Testing
-------

[](#testing)

This package is tested using Orchestra Testbench to ensure compatibility with Laravel applications.

---

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

50d ago

Major Versions

v1.0.0 → v2.0.02026-05-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/30828e96e70ef1fe52ce906f3a6ec9883fd4fce1e8c0181ca2ea49ce5541b0d2?d=identicon)[AffanAbd97](/maintainers/AffanAbd97)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sazl-laravel-repokit/health.svg)

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

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.3k](/packages/laravel-sail)[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k90.5k1](/packages/mike-bronner-laravel-model-caching)

PHPackages © 2026

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