nodirjon/crud-generator
Composer 安装命令:
composer require nodirjon/crud-generator
包简介
A Laravel CRUD generator that creates Controller, Service, Repository, DTO, and Request classes from a single Artisan command. Supports automatic file/media upload handling.
README 文档
README
A powerful Laravel CRUD generator that scaffolds a complete layered architecture from a single Artisan command — Controller → Service → Repository → DTO → Requests — with automatic image/video upload handling.
Features
- ✅ Generates Controller, Service, Repository, DTO, StoreRequest, UpdateRequest in one command
- ✅ Reads model
$fillablefields automatically and generates proper validation rules - ✅ Auto-detects file/media fields (
image,photo,video,avatar,cover,thumbnail,file,media,attachment,banner,poster) and:- Adds
nullable|file|mimes:...validation rules - Stores files in
storage/app/public/{model}/{id}/folder - Deletes old files on update (no storage pollution)
- Deletes all files and the folder on delete
- Adds
- ✅ Consistent method names across all layers (
getAll,findById,create,update,delete) - ✅ Supports Laravel 10, 11, and 12
- ✅ Auto-registered via Laravel Package Discovery (no manual config needed)
Requirements
- PHP >= 8.2
- Laravel >= 10.x
Installation
composer require nodirjon/crud-generator
The package is auto-discovered by Laravel — no need to add anything to config/app.php.
Usage
1. Create your Model and Migration
php artisan make:model Post -m
Add your fields to the migration and run it:
php artisan migrate
Define $fillable in your model:
// app/Models/Post.php protected $fillable = ['title', 'body', 'cover_image', 'video'];
2. Generate CRUD
php artisan make:crud Post
Output:
Created: app/Http/Controllers/PostController.php
Created: app/Http/Requests/Post/StorePostRequest.php
Created: app/Http/Requests/Post/UpdatePostRequest.php
Created: app/Services/PostService.php
Created: app/Repositories/PostRepository.php
Created: app/DTO/PostDTO.php
CRUD for Post generated successfully!
File fields detected: cover_image, video
Files will be stored in: storage/app/public/post/{id}/
3. Register the route
// routes/api.php Route::apiResource('posts', PostController::class);
4. Link storage (first time only)
php artisan storage:link
Generated File Structure
app/
├── Http/
│ ├── Controllers/
│ │ └── PostController.php # index, store, show, update, destroy
│ └── Requests/
│ └── Post/
│ ├── StorePostRequest.php # validation rules (auto-generated)
│ └── UpdatePostRequest.php
├── Services/
│ └── PostService.php # business logic + file handling
├── Repositories/
│ └── PostRepository.php # database queries
└── DTO/
└── PostDTO.php # data transfer object
File Upload Behavior
When a model has fields containing file-related keywords (image, photo, video, avatar, cover, thumbnail, file, media, attachment, banner, poster), the generator automatically:
| Action | Behavior |
|---|---|
| Create | Uploads file → storage/public/{model}/tmp/ → moves to {model}/{id}/ after creation |
| Update | Deletes old file → uploads new file to {model}/{id}/ |
| Delete | Deletes all files and removes the {model}/{id}/ directory |
Storage path example
storage/app/public/
└── post/
└── 42/
├── cover_image_xR3kL2.jpg
└── video_pQ7mN9.mp4
Public URL:
/storage/post/42/cover_image_xR3kL2.jpg
Auto-detected File Field Keywords
The command detects the following keywords (case-insensitive, anywhere in the field name):
image · photo · video · avatar · cover · thumbnail · file · media · attachment · banner · poster
Examples: profile_photo, cover_image, intro_video, user_avatar are all detected automatically.
Customization
After generation, you can freely customize any generated file. The service's $fileFields and $folder properties can be modified:
// app/Services/PostService.php protected string $folder = 'posts'; // change storage folder name protected array $fileFields = ['cover_image']; // add/remove file fields
License
MIT — see LICENSE for details.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-13