一键导入
goravel-crud-service
Generate the service layer for a Goravel entity with builder pattern configuration. Use after model generation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate the service layer for a Goravel entity with builder pattern configuration. Use after model generation.
用 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-service |
| description | Generate the service layer for a Goravel entity with builder pattern configuration. Use after model generation. |
| argument-hint | [ModelName] [entity_name] |
| allowed-tools | Bash, Read, Write, Edit, Grep, Glob |
Generate service for $ARGUMENTS.
go run . artisan make:svc --model=<ModelName> <entity_name>
This creates app/services/<entity_name>_service.go.
The generated service uses contracts.NewServiceBuilder. You MUST configure these:
service := contracts.NewServiceBuilder[models.ModelName]("table_name", "id").
// REQUIRED: At least one search field
WithSearchFields("title", "description", "name").
// REQUIRED: Define sortable columns
WithSortFields("id", "created_at", "updated_at", "title").
// REQUIRED: At least one validation rule
WithValidationRules(map[string]interface{}{
"title": "required|max_len:255",
"name": "required|max_len:100",
}).
Build()
// Filter fields (for URL param-based filtering)
WithFilterFields("status", "category", "district").
// Default sort order
WithDefaultSort("created_at", "DESC").
// Eager load relationships
WithRelations("Creator", "Updater").
// Enable scoped permissions (user/role/global)
WithScopeFiltering("service_name", "created_by").
// Lifecycle hooks
WithBeforeCreate(func(data map[string]interface{}) error {
// Custom pre-create logic
return nil
}).
WithAfterCreate(func(model *models.ModelName) error {
// Custom post-create logic
return nil
}).
WithBeforeUpdate(func(id uint, data map[string]interface{}) error {
return nil
}).
// Custom query modifications
WithCustomQuery(func(query orm.Query) orm.Query {
return query.Where("is_active = ?", true)
}).
See app/services/book_service.go for the canonical service implementation.
Key things to match:
NewServiceBuilder[models.Book]("books", "id") - generic type + table + primary keyWith* methods calledIf your frontend sends camelCase sort fields, add a column mapping:
func (s *EntityService) GetColumnMapping() map[string]string {
mapping := s.CrudServiceContract.GetColumnMapping()
mapping["configType"] = "config_type"
mapping["createdAt"] = "created_at"
mapping["updatedAt"] = "updated_at"
return mapping
}
func (s *EntityService) GetEntityStatistics() (map[string]interface{}, error) {
var totalCount int64
totalCount, _ = facades.Orm().Query().Model(&models.Entity{}).Count()
return map[string]interface{}{
"totalCount": totalCount,
}, nil
}
After configuring the service builder:
# Check for issues in the service
go vet ./app/services/...
# Confirm full project compiles
go build ./...
Run /goravel-crud-permissions to register permissions for this entity.