backend-enum-use

majiayu000 的头像作者 majiayu000

创建遵循Laravel约定的功能丰富的PHP枚举,使用全部大写蛇形命名(SCREAMING_SNAKE_CASE),支持字符串或整型枚举值,提供标签和比较的辅助方法,验证规则,以及全面的Pest测试。当将硬编码的字符串或魔法数字转换为类型安全的枚举,创建如状态、类型、角色或分类等分类数据类型,为表单或API添加基于枚举的验证,将魔法字符串重构为结构化类型,或在应用中定义一组允许的值时,使用此技能。此技能适用于在app/Enums/目录中工作,创建枚举类,为模型添加枚举转换或实现枚举验证规则。

📖 中文导读:创建遵循Laravel约定的功能丰富的PHP枚举,使用全部大写蛇形命名(SCREAMING_SNAKE_CASE),支持字符串或整型枚举值,提供标签和比较的辅助方法,验证规则,以及全面的Pest测试。当将硬编码的字符串或魔法数字转换为类型安全的枚举,创建如状态、类型、角色或分类等分类数据类型,为表单或API添加基于枚举的验证,将魔法字符串重构为结构化类型,或在应用中定义一组允许的值时,使用此技能。此技能适用于在app/Enums/目录中工作,创建枚举类,为模型添加枚举转换或实现枚举验证规则。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: Backend Enum Use description: Create feature-rich PHP enums following Laravel conventions with SCREAMING_SNAKE_CASE case names, backed enum values (string or int), helper methods for labels and comparisons, validation rules, and comprehensive Pest tests. Use this skill when converting hardcoded strings or magic numbers to type-safe enums, creating categorical data types like statuses, types, roles or categories, adding enum-based validation to forms or APIs, refactoring magic strings into structured types, or defining a fixed set of allowed values in your application. This skill applies when working on files in app/Enums/ directory, creating enum classes, adding enum casts to models, or implementing enum validation rules.

Backend Enum Use

When to use this skill

  • When converting hardcoded strings or magic numbers to type-safe enums
  • When creating categorical data types (statuses, types, roles, categories, etc.)
  • When adding enum-based validation to forms, API requests, or database columns
  • When refactoring magic strings into structured, type-safe types
  • When defining a fixed set of allowed values for a field or property
  • When implementing state machines or workflow statuses
  • When working on files in app/Enums/ directory
  • When creating enum classes with helper methods (label(), description(), etc.)
  • When adding enum casts to Eloquent models
  • When implementing Laravel validation rules for enum values
  • When writing tests for enum functionality and transitions

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle backend enum use.

Instructions

For details, refer to the information provided in this file: backend enum use