PHPackages                             rakib-587/laravel-make-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. rakib-587/laravel-make-repository

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

rakib-587/laravel-make-repository
=================================

Laravel Artisan command to generate repositories with optional model binding.

v2.1.2(1mo ago)117MITPHPPHP &gt;=8.1

Since Jun 22Pushed 1mo agoCompare

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

READMEChangelogDependencies (2)Versions (8)Used By (0)

Laravel Make Repository
=======================

[](#laravel-make-repository)

A lightweight Laravel package that provides Artisan commands to generate Repository classes following a clean and extendable pattern. Supports optional model binding and integrated model creation.

Supported Laravel versions: 10, 11, 12, and 13. This package is Laravel-only and is not intended for non-Laravel projects.

---

🚨 Breaking Changes (Major Release)
----------------------------------

[](#-breaking-changes-major-release)

If you are upgrading from a previous major version, review these changes:

- `getAll()` has been removed from the base repository.
- Use `all()` instead.
- The package is now Laravel-only (no non-Laravel support target).
- Base repository API now follows stricter typing.

Quick migration example:

```
// Before
UserRepository::getAll();

// After
UserRepository::all();
```

---

📦 Installation
--------------

[](#-installation)

Require the package via Composer:

```
composer require rakib-587/laravel-make-repository
```

If auto-discovery doesn't work, manually register the service provider in `config/app.php`:

```
'providers' => [
    Rakib\MakeRepository\MakeRepositoryServiceProvider::class,
],
```

---

⚙️ Usage
--------

[](#️-usage)

### ➤ Create a Repository for an Existing Model

[](#-create-a-repository-for-an-existing-model)

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

This will generate:

- `app/Repositories/UserRepository.php`
- Uses `App\Models\User` as the associated model (automatically inferred)

---

### ➤ Create a Repository with an Explicit Model

[](#-create-a-repository-with-an-explicit-model)

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

This allows you to manually specify the model class to be used inside the repository.

---

### ➤ Create a Model with a Repository in One Command

[](#-create-a-model-with-a-repository-in-one-command)

```
php artisan make:model Product --repo
```

This command:

- Creates `app/Models/Product.php`
- Creates `app/Repositories/ProductRepository.php`
- Links the repository to the model automatically

Nested models are also supported:

```
php artisan make:model Admin/Test --repo
```

This generates:

- `app/Models/Admin/Test.php`
- `app/Repositories/Admin/TestRepository.php`

---

🧱 Base Repository API
---------------------

[](#-base-repository-api)

Generated repositories extend a typed base class.

```
namespace App\Repositories;

use App\Models\User;
use Rakib\MakeRepository\Repository;

/**
 * @extends Repository
 */
class UserRepository extends Repository
{
    public static function model(): string
    {
        return User::class;
    }
}
```

Available base methods:

- `query(): Builder`
- `all(array|string $columns = ['*']): Collection`
- `first(array|string $columns = ['*']): ?Model`
- `firstOrFail(array|string $columns = ['*']): Model`
- `find(int|string $id, array|string $columns = ['*']): ?Model`
- `findOrFail(int|string $id, array|string $columns = ['*']): Model`
- `findMany(array $ids, array|string $columns = ['*']): Collection`
- `create(array $attributes): Model`
- `update(Model $model, array $attributes): bool`
- `delete(Model $model): bool|null` (delete by model instance)
- `destroy(int|string|array $ids): int` (delete by id or id list)

> Note: mass assignment rules still apply to `create()` and `update()`. Ensure your model has the proper `$fillable` or `$guarded` configuration.

---

🧩 Customizing the Stub
----------------------

[](#-customizing-the-stub)

The repository class is generated using a stub file that defines its structure and placeholders.

By default, the command looks for a local stub file in your Laravel project:

```
stubs/repository.stub

```

If the file **does not exist**, it will gracefully fall back to using the default stub provided by the package.

---

### ✏️ How to Customize

[](#️-how-to-customize)

To customize the repository structure, first publish the stub file into your project:

```
php artisan vendor:publish --tag=make-repository-stubs
```

This will copy the stub to:

```
stubs/repository.stub

```

You can now edit the stub to change the generated structure.

Available placeholders:

- `{{ Namespace }}` — The repository namespace (e.g., `App\Repositories\Admin`)
- `{{ ClassName }}` — The repository class name only (e.g., `UserRepository`)
- `{{ ModelClass }}` — The fully qualified model class used in `use` statements (e.g., `App\Models\Admin\User`)
- `{{ ModelName }}` — The model short class name used in phpdoc and return type reference (e.g., `User`)

Once the stub exists in your project, it will automatically be used for all future repository generations.

---

📁 Output Structure Example
--------------------------

[](#-output-structure-example)

When you run:

```
php artisan make:repository Order
```

You'll get:

```
// app/Repositories/OrderRepository.php

namespace App\Repositories;

use App\Models\Order;
use Rakib\MakeRepository\Repository;

class OrderRepository extends Repository
{
    public static function model(): string
    {
        return Order::class;
    }
}
```

---

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

🙌 Author
--------

[](#-author)

**Md Rakibul Islam**GitHub: [@rakib-587](https://github.com/rakib-587)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance92

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Recently: every ~71 days

Total

7

Last Release

39d ago

Major Versions

v1.0.2 → v2.0.02026-03-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/80beb7f5b38ba66e393dd85db0294a6173d022ceb7a534c24d1bbd6980dff6bd?d=identicon)[rakib-587](/maintainers/rakib-587)

---

Top Contributors

[![rakib-587](https://avatars.githubusercontent.com/u/81109867?v=4)](https://github.com/rakib-587 "rakib-587 (12 commits)")

---

Tags

laravelrepositorylaravel-repositoryrakib-587laravel-make-repository

### Embed Badge

![Health badge](/badges/rakib-587-laravel-make-repository/health.svg)

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

###  Alternatives

[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)[mckenziearts/laravel-command

A simple Laravel package to provide artisan new commands

321.2k](/packages/mckenziearts-laravel-command)

PHPackages © 2026

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