一键导入
goravel-crud-controller
Generate API controller for a Goravel entity with permission checking and Swagger annotations. Use after creating request validators.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate API controller for a Goravel entity with permission checking and Swagger annotations. Use after creating request validators.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create a broadcast notification system that sends notifications and messages to eligible users based on entity-specific criteria. Use when adding a new entity type that needs to notify users when records are created, updated, or published.
Guide for building non-CRUD pages with consistent design. Use when creating portal pages, custom views, detail modals, sidebar widgets, notification drawers, or any page that is not a standard CRUD table. Covers fullscreen modals, minimal text patterns, calendar widgets, doorbell notifications, optimistic updates, and CrudPage read-only integration.
Guide for building dashboards, charts, KPI cards, and data visualizations. Use when creating dashboard pages, adding charts to features, building stat displays, aggregating data for visual presentation, or implementing export (CSV/PNG/fullscreen) for charts. Based on the Books dashboard implementation using Recharts and shadcn/ui chart components.
Deploy the application to staging or production. Validates, builds, pushes Docker image, deploys via Helm, and runs smoke tests.
Run a comprehensive E2E browser test suite for a newly scaffolded Goravel entity. Tests navigation, CRUD operations, search, filters, row actions, form validation, FK dropdowns, and cross-entity integration using Playwright MCP.
Create a Go database seeder for a Goravel entity with 25+ realistic records. Covers all status/enum values, diverse data for sorting/pagination testing, and proper nullable field handling.
| name | goravel-crud-controller |
| description | Generate API controller for a Goravel entity with permission checking and Swagger annotations. Use after creating request validators. |
| argument-hint | [entity_name] |
| allowed-tools | Bash, Read, Write, Edit, Grep, Glob |
Generate controller for $ARGUMENTS.
go run . artisan make:ctrl --model=<entity_name> <entity_name>
This creates app/http/controllers/<entity_name>s/<entity_name>_controller.go.
Generator may use underscores instead of CamelCase:
// WRONG (generator may create):
auth.ServiceBusiness_formalisations
// CORRECT (must match permission_constants.go):
auth.ServiceBusinessFormalisation
The auth.Service* constant in the controller MUST match what you registered in permission_constants.go:
// Check permission_constants.go for the exact constant name
crudController := contracts.NewCrudController[
models.Entity,
*requests.EntityCreateRequest,
*requests.EntityUpdateRequest,
](
"entity", // resource name for logging
entityService, // service instance
).
WithAuthChecker(func(ctx http.Context, action string, resource interface{}) error {
permHelper := auth.GetPermissionHelper()
switch action {
case "viewAny", "view":
if !permHelper.CheckServicePermission(ctx, auth.ServiceEntity, auth.PermissionRead) {
return fmt.Errorf("unauthorized")
}
case "create":
if !permHelper.CheckServicePermission(ctx, auth.ServiceEntity, auth.PermissionCreate) {
return fmt.Errorf("unauthorized")
}
case "update":
if !permHelper.CheckServicePermission(ctx, auth.ServiceEntity, auth.PermissionUpdate) {
return fmt.Errorf("unauthorized")
}
case "delete":
if !permHelper.CheckServicePermission(ctx, auth.ServiceEntity, auth.PermissionDelete) {
return fmt.Errorf("unauthorized")
}
}
return nil
}).
Build()
func NewEntityController() *EntityController {
entityService := services.NewEntityService()
// ... build crudController
return &EntityController{
CrudController: crudController,
}
}
See app/http/controllers/books/book_controller.go for:
WithAuthCheckerThe CrudController automatically provides:
Index - List with pagination, sorting, filteringShow - Get by IDStore - Create new recordUpdate - Update existing recordDelete - Soft deleteSearch - Keyword searchFilterMetadata - Available filter optionsfunc (c *EntityController) Statistics(ctx http.Context) http.Response {
// Check permission
permHelper := auth.GetPermissionHelper()
if !permHelper.CheckServicePermission(ctx, auth.ServiceEntity, auth.PermissionRead) {
return ctx.Response().Status(403).Json(map[string]interface{}{
"error": "Unauthorized",
})
}
stats, err := c.entityService.GetEntityStatistics()
if err != nil {
return ctx.Response().Status(500).Json(map[string]interface{}{
"error": err.Error(),
})
}
return ctx.Response().Json(200, map[string]interface{}{
"success": true,
"data": stats,
})
}
After fixing the controller:
# Vet the controller package
go vet ./app/http/controllers/...
# Confirm full project compiles (catches service constant mismatches)
go build ./...
Run /goravel-crud-routes to register the API routes.