AgentSkillsCN

Backend Models

按照最佳实践设计和实现数据库模型,采用清晰的单数命名、恰当的时间戳、合适的数据类型、数据库约束、关系定义和多层验证。在创建新Eloquent模型、定义模型关系(hasMany、belongsTo等)、添加可填充或受保护属性、实现属性的模型转换、定义数据库约束和外键、或处理模型工厂和种子器时使用此技能。在app/Models/目录的文件上工作、创建模型类、定义表结构或实现模型访问器和修改器时适用。

SKILL.md
--- frontmatter
name: Backend Models
description: Design and implement database models following best practices with clear singular naming, proper timestamps, appropriate data types, database constraints, relationship definitions, and validation at multiple layers. Use this skill when creating new Eloquent models, defining model relationships (hasMany, belongsTo, etc.), adding fillable or guarded properties, implementing model casts for attributes, defining database constraints and foreign keys, or working with model factories and seeders. This skill applies when working on files in app/Models/ directory, creating model classes, defining table structures, or implementing model accessors and mutators.

Backend Models

When to use this skill

  • When creating new Eloquent models for database tables
  • When defining model relationships (hasMany, belongsTo, belongsToMany, hasOne, etc.)
  • When adding fillable or guarded properties to control mass assignment
  • When implementing model casts for attributes (dates, JSON, enums, etc.)
  • When defining database constraints (NOT NULL, UNIQUE, foreign keys)
  • When working with model factories for testing or seeding
  • When working on files in app/Models/ directory
  • When creating model classes or updating existing models
  • When implementing model accessors and mutators
  • When defining custom model methods or scopes
  • When choosing appropriate data types for model properties
  • When implementing model validation logic

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

Instructions

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