win-aung/laravel-entity-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

win-aung/laravel-entity-generator

Composer 安装命令:

composer require win-aung/laravel-entity-generator

包简介

A Laravel package to generate CRUD entities with controllers, models, services, requests, resources, and migrations using service design pattern

README 文档

README

A powerful Laravel package that generates complete CRUD entities with controllers, models, services, requests, resources, and migrations using the service design pattern.

Features

  • 🚀 Fast Entity Generation: Generate complete CRUD entities with a single command
  • 🏗️ Service Pattern: Built-in service layer for business logic separation
  • 📝 Auto-generated Files: Controllers, Models, Services, Requests, Resources, and Migrations
  • Laravel Best Practices: Follows Laravel conventions and design patterns
  • 🔧 Customizable: Easy to customize stubs and configuration
  • 💪 Production Ready: Includes proper error handling and transactions

Installation

Via Composer

composer require win-aung/laravel-entity-generator:dev-main

Usage

Basic Usage

Generate a complete entity with all CRUD operations:

php artisan make:entity User

This will create:

  • app/Services/User/UserService.php - Service layer for business logic
  • app/Http/Controllers/UserController.php - RESTful controller with CRUD methods
  • app/Models/User.php - Eloquent model
  • app/Http/Requests/UserRequest.php - Form request validation
  • app/Http/Resources/UserResource.php - API resource for JSON responses
  • database/migrations/*_users_table.php - Database migration

Force Overwrite

To overwrite existing files:

php artisan make:entity User --force

Interactive Mode

If files already exist, the command will ask for confirmation:

php artisan make:entity User
# Will prompt: "File already exists: app/Http/Controllers/UserController.php. Overwrite?"

Generated Files Structure

Controller (UserController.php)

<?php

namespace App\Http\Controllers;

use App\Http\Requests\UserRequest;
use App\Services\User\UserService;

class UserController extends Controller
{
    protected $userService;

    public function __construct(UserService $userService)
    {
        $this->userService = $userService;
    }

    public function index()
    {
        return $this->sendResponse($this->userService->getAll(), 200, 'User retrieved');
    }

    public function store(UserRequest $request)
    {
        $data = $this->userService->create($request->all());
        return $this->sendResponse($data, 201, 'User created');
    }

    // ... other CRUD methods
}

Service (UserService.php)

<?php

namespace App\Services\User;

use App\Models\User;

class UserService
{
    protected $model;

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

    public function getAll()
    {
        return $this->model->all();
    }

    public function create($data)
    {
        return $this->model->create($data);
    }

    // ... other methods
}

Configuration

Publish the configuration file to customize the package:

php artisan vendor:publish --tag=config

This will create config/laravel-entity-generator.php with the following options:

return [
    'service_namespace' => 'App\\Services',
    'controller_namespace' => 'App\\Http\\Controllers',
    'model_namespace' => 'App\\Models',
    'request_namespace' => 'App\\Http\\Requests',
    'resource_namespace' => 'App\\Http\\Resources',
    'generate_repository' => false,
    'generate_tests' => false,
    'directory_permissions' => 0755,
];

Customization

Custom Stubs

You can customize the generated code by publishing and modifying the stub files:

  1. Publish the stubs:
php artisan vendor:publish --tag=stubs
  1. Modify the stub files in resources/stubs/

  2. Update the configuration to use your custom stubs:

'stub_paths' => [
    'controller' => resource_path('stubs/controller.crud.stub'),
    'service' => resource_path('stubs/service.stub'),
],

API Endpoints

The generated controller provides these RESTful endpoints:

  • GET /users - List all users
  • POST /users - Create a new user
  • GET /users/{id} - Show a specific user
  • PUT /users/{id} - Update a user
  • DELETE /users/{id} - Delete a user

Response Format

All API responses follow a consistent format:

Success Response

{
    "success": true,
    "data": {...},
    "message": "User created"
}

Error Response

{
    "success": false,
    "message": "User not found"
}

Requirements

  • PHP >= 8.0
  • Laravel >= 9.0

Testing

composer test

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

The MIT License (MIT). Please see License File for more information.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

Made with ❤️ for the Laravel community

win-aung/laravel-entity-generator 适用场景与选型建议

win-aung/laravel-entity-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 win-aung/laravel-entity-generator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-23