scaffold-crud
为实体(操作、控制器、请求、页面、路由)构建完整的 CRUD 功能。用于从头开始构建新功能时(例如,“在学术模块中为事件构建 CRUD”)
📖 中文导读:为实体(操作、控制器、请求、页面、路由)构建完整的 CRUD 功能。用于从头开始构建新功能时(例如,“在学术模块中为事件构建 CRUD”) 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: scaffold-crud description: Scaffolds a complete CRUD feature for an entity (Actions, Controller, Requests, Pages, Routes). Use when building a new feature from scratch (e.g., "Scaffold CRUD for Events in Academic module"). allowed-tools: Bash, Write, Read
Scaffold CRUD Feature
This skill helps generate the full stack of files needed for a standard CRUD feature in the Modular Monolith architecture.
Instructions
Analyze Request:
- Module: (e.g.,
Academic) - Entity: (e.g.,
Course) - Portal:
Admin(default) orStudent.
- Module: (e.g.,
Plan the Files: Create a checklist of files to generate using the specific single-purpose skills (or manually if skills can't be called directly).
Backend:
Model:app/Modules/{Module}/Models/{Entity}.phpMigration:database/migrations/xxxx_xx_xx_create_{table}_table.phpActions:Create{Entity}Action,Update{Entity}Action,Delete{Entity}Action.Query:List{Entity}Query(for Index),Get{Entity}Query(for Show/Edit).Requests:Create{Entity}Request,Update{Entity}Request.Controller:Http/Controllers/Web/{Portal}/{Entity}Controller.php.Policy:Policies/{Entity}Policy.php.Routes: Add toroutes/web.phpin the module.
Frontend (Inertia):
Index.vue: List with DataTable.Create.vue: Form for creating.Edit.vue: Form for editing.
Execute (Step-by-Step):
- Don't try to write all files in one turn.
- Start with Model & Migration.
- Then Actions & Queries.
- Then Requests & Policy.
- Then Controller & Routes.
- Finally Vue Pages.
Wiring:
- Ensure the Controller calls the Actions and Queries.
- Ensure the Vue pages use the correct Routes.
Template: Route Registration
// app/Modules/{Module}/routes/web.php
use App\Modules\Academic\Http\Controllers\Web\Admin\CourseController;
Route::middleware(['auth', 'verified'])->group(function () {
Route::resource('academic/courses', CourseController::class)
->names('academic.courses');
});
Best Practices
- Consistency: Ensure the
route()names in Vue match the names defined inroutes/web.php. - Authorization: Remind the user to register the Policy and Permissions.
- Validation: Ensure Requests are strictly typed.