承接 rakib-587/laravel-make-repository 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rakib-587/laravel-make-repository

Composer 安装命令:

composer require rakib-587/laravel-make-repository

包简介

Laravel Artisan command to generate repositories with optional model binding.

README 文档

README

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)

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

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

➤ 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

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

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

Generated repositories extend a typed base class.

namespace App\Repositories;

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

/**
 * @extends Repository<User>
 */
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

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

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

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

This package is open-sourced software licensed under the MIT license.

🙌 Author

Md Rakibul Islam GitHub: @rakib-587

rakib-587/laravel-make-repository 适用场景与选型建议

rakib-587/laravel-make-repository 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 06 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「repository」 「laravel」 「laravel-repository」 「rakib-587」 「laravel-make-repository」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rakib-587/laravel-make-repository 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rakib-587/laravel-make-repository 我们能提供哪些服务?
定制开发 / 二次开发

基于 rakib-587/laravel-make-repository 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-22