From laraclaude
Deep analysis of a Laravel Eloquent model - relationships, scopes, casts, fillable, observers, keepers, actions.
How this skill is triggered — by the user, by Claude, or both
Slash command
/laraclaude:analyze-model [analyze | fix | fix --dry-run | ModelName | fix ModelName][analyze | fix | fix --dry-run | ModelName | fix ModelName]This skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Perform a comprehensive analysis of a Laravel Eloquent model, extracting all relevant information about its structure, relationships, behaviors, and potential issues.
Perform a comprehensive analysis of a Laravel Eloquent model, extracting all relevant information about its structure, relationships, behaviors, and potential issues.
| Subcommand | Description |
|---|---|
| (no argument) | List all models and ask which to analyze. Read-only report. |
fix | Analyze all models and auto-fix common issues (missing fillable, broken casts, etc.) with confirmation before each change. |
fix --dry-run | Show what fixes would be applied across all models without changing anything. |
[ModelName] | Analyze a specific model. Read-only report. |
fix [ModelName] | Analyze and fix issues in a specific model, with confirmation before each change. |
[ModelName] argument is provided:
app/Models/{ModelName}.php using Glob.app/Models/ directory.app/ directory for a class with that name.Glob to list all files in app/Models/*.php.Use Read to load the full model file. Extract the following sections:
#[KeptBy(...)], #[UsesOrigin(...)], etc.)$table property or conventional)casts() method -- list all casts with their typesFor each relationship method, extract:
Display as a structured list:
RELATIONSHIPS
==============
belongsTo:
- organization() -> Organization::class (FK: organization_id)
- office() -> Office::class (FK: office_id)
- user() -> User::class (FK: user_id)
hasMany:
- properties() -> Property::class (FK: client_id)
- operations() -> Operation::class (FK: client_seller_id)
belongsToMany:
- tags() -> Tag::class (pivot: client_tag, columns: [])
scopeActive, scopeForUser, etc.)booted() or via attributes)Attribute::make(get: ..., set: ...)getXAttribute(), setXAttribute()$appends arrayapp/Observers/{ModelName}Observer.php#[KeptBy(KeeperClass::class)] attributegetX() methods$actions array propertyhandle() method signatureboot(), booted() -- any event listeners or global scopesGrep to search for Schema::create('{table_name}'.$fillable:
$fillable (and not in standard exclusions like id, timestamps, etc.)$fillable but NOT in migration (possibly computed or from a different source)Scan for these common problems:
$fillable or $guarded.belongsTo relationship where the FK column doesn't have a foreign key constraint in the migration.$this->relationship without the relationship being commonly eager-loaded.SoftDeletes trait but migration doesn't have softDeletes(), or vice versa.Create a text-based relationship diagram showing how this model connects to others:
+------------------+
| Organization |
+------------------+
|
belongsTo
|
+----------+ +-----------+ +----------+
| Office |<-------| Client |------->| User |
+----------+ +-----------+ +----------+
belongsTo | | belongsTo
hasMany belongsToMany
| |
+-----------+ +------+
| Property | | Tag |
+-----------+ +------+
Keep the diagram focused on direct relationships (1 level deep). For models with many relationships, group by relationship type.
Output all findings in a well-structured format with clear section headers. Use code blocks for code snippets and tables for tabular data.
End with a summary:
MODEL SUMMARY: Client
======================
Table: clients
Traits: 5 (HasFactory, SoftDeletes, HasActions, HasKeepers, Notifiable)
Fillable fields: 22
Relationships: 12 (4 belongsTo, 5 hasMany, 2 belongsToMany, 1 morphMany)
Scopes: 3
Accessors: 4
Actions: 3
Potential issues: 2
fix or fix [ModelName])When running in fix mode, automatically apply fixes for detected issues with confirmation before each change:
$fillable array (excluding id, timestamps, soft deletes, and auto-generated fields).belongsTo methods for FK columns that lack corresponding relationship methods.SoftDeletes trait if migration has softDeletes() but model lacks the trait, or vice versa.Each fix requires explicit user confirmation before applying.
fix --dry-run)Show all the fixes that would be applied (same as fix mode) but do not write any changes. Display the before/after diff for each proposed change.
npx claudepluginhub edulazaro/laraclaude --plugin laraclaudeDetect broken, orphaned, or missing foreign key constraints in Laravel migrations and models.
Provides complete Eloquent ORM guidance for Laravel 13 with PHP 8.3 Attributes (#[Table], #[Fillable], #[Casts]) for models, relationships, queries, observers, and factories. Activates when working with database models.
Provides best practices for Eloquent ORM: N+1 prevention, query scopes, mass assignment safety, relations, and aggregate performance.