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 logicapp/Http/Controllers/UserController.php- RESTful controller with CRUD methodsapp/Models/User.php- Eloquent modelapp/Http/Requests/UserRequest.php- Form request validationapp/Http/Resources/UserResource.php- API resource for JSON responsesdatabase/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:
- Publish the stubs:
php artisan vendor:publish --tag=stubs
-
Modify the stub files in
resources/stubs/ -
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 usersPOST /users- Create a new userGET /users/{id}- Show a specific userPUT /users/{id}- Update a userDELETE /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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
- Win Aung
- All Contributors
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 win-aung/laravel-entity-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
Memio's PrettyPrinter, used to generate PHP code from given Model
Lets you add foreign keys in a swift! Foreign key adder in laravel migration.
Manage PostgreSQL schemas in Laravel applications
Bitrix db migration core libs
Create mail from controller action render
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-23