返回 Skill 列表
extension
分类: 开发与工程无需 API Key

Backend Enum Use

按照Laravel约定创建功能丰富的PHP枚举,使用SCREAMING_SNAKE_CASE命名方式,支持枚举值(字符串或整数),提供用于标签和比较的帮助方法、验证规则以及全面的Pest测试。在将硬编码的字符串或魔术数字转换为类型安全的枚举、创建如状态、类型、角色或类别的分类数据类型、向表单或API中添加基于枚举的验证、将魔术字符串重构为结构化类型,或者在应用程序中定义一组固定的允许值时,请使用此技能。当处理app/Enums/目录下的文件、创建枚举类、向模型添加枚举转换或实现枚举验证规则时,这项技能非常适用。

person作者: jakexiaohubgithub

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