承接 arlx/repository-generator 相关项目开发

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

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

arlx/repository-generator

最新稳定版本:v3.0.24

Composer 安装命令:

composer require arlx/repository-generator

包简介

README 文档

README

Latest Version on Packagist Total Downloads License

Table of Contents

    <li><a href="#features">Features</a></li>
    <li>
        <a href="#getting-started">Getting started</a>
        <ul>
            <li><a href="#installation">Installation</a></li>
        </ul>
    </li>
    <li>
      <a href="#usage">Usage</a>
      <ul>
        <li><a href="#generating-models">Generating models</a></li>
        <li><a href="#generating-repositories">Generating repositories</a></li>
        <li><a href="#generating-controllers">Generating controllers</a></li>
        <li><a href="#dependency-injection">Dependency Injection</a></li>
      </ul>
    </li>
    <li><a href="#auto-binding">Auto binding</a></li>
    <li><a href="#contributing">Contributing</a></li>
    <li><a href="#license">License</a></li>
    

Features

With this package you can generate models, repositories, and controllers using custom artisan commands.
The repository generator will also bind interfaces automatically to the Laravel Service Container for dependency injection.

Installation

Require the Laravel Repository Generator with composer.

composer require arlx/repository-generator

Usage

Generating models

Run the following command to generate a model:

php artisan geek:model User

This command will generate the following file:

app\Models\User.php

You can also include optional flags:

  • -m or --migration – generate a migration
  • -r or --resource – generate a resource controller
  • --repo – generate repository & interface
  • -a or --all – generate all of the above at once

Example:

php artisan geek:model User -mr --repo

Or simply:

php artisan geek:model User --all

The generated model structure looks like this:

<?php

namespace App\Models;

use App\Traits\HasUUID;
use Askedio\SoftCascade\Traits\SoftCascadeTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Wildside\Userstamps\Userstamps;

class User extends Model
{
    use HasFactory, SoftDeletes, SoftCascadeTrait, Userstamps, HasUUID;

    protected $guarded = [
        'id',
        'id_hash'
    ];

    protected $casts = [
        'created_at' => 'string',
        'updated_at' => 'string',
        'deleted_at' => 'string',
    ];

    protected $softCascade = [];
}

Generating repositories

Run the following command:

php artisan geek:repository UserRepository

This example will generate the following files:

app\Repositories\UserRepository
app\Interfaces\UserInterface

Generating controllers

Run the following command:

php artisan geek:controller Api/UserController --swagger-api=/api/master/user

note: --swagger-api is optional and will generate swagger tags and path

This example will generate the following file:

app\Http\Api\UserController

Dependency Injection

Next we have to inject the interface into the constructor of our controller.
For this example we will use the UserController.

<?php

namespace App\Http\Controllers;

use App\Repositories\UserInterface;

class UserController extends Controller
{
    public function __construct(
        private UserInterface $userRepository
    ) {}

    // your controller functions
}

Auto binding

The package will automatically bind the repository interfaces with the implementations,
so you can directly inject the interface into your controllers.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

The MIT License (MIT).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-13