Agent skill
models
Eloquent model conventions covering mass assignment, casts, relationships, section headers, and activity logging. Every model must follow these structural rules.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/models-codebar-ag-coding-guidelines
SKILL.md
Name: Models Description: Eloquent model conventions covering mass assignment, casts, relationships, section headers, and activity logging. Every model must follow these structural rules. Compatible Agents: general-purpose, backend Tags: app/Models/**/*.php, laravel, php, backend, eloquent, model, database
Rules
- Use
$guarded = []— never use$fillablearrays - Define
casts()as a method, not a property - Cast enums, dates, decimals, and JSON in
casts() - Add the
LogsActivitytrait on all business models - Configure
getActivitylogOptions()withlogAll(),logOnlyDirty(),dontSubmitEmptyLogs() - Use typed return types on all relationship methods (
HasMany,BelongsTo, etc.) - Every new model must have a corresponding factory in
database/factories/ - Group model code with section comment headers:
// --- Relationships ---,// --- Status Helpers ---, etc.
Examples
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
class Invoice extends Model
{
use LogsActivity;
protected $guarded = [];
protected function casts(): array
{
return [
'status' => Status::class,
'due_date' => 'date',
'amount' => 'decimal:2',
];
}
// --- Relationships ---
public function lines(): HasMany
{
return $this->hasMany(InvoiceLine::class);
}
// --- Status Helpers ---
public function isDraft(): bool
{
return $this->status === Status::Draft;
}
public function isPaid(): bool
{
return $this->status === Status::Paid;
}
// --- Activity Log ---
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logAll()
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
}
Anti-Patterns
- Using
$fillablearrays instead of$guarded = [] - Defining
$castsas a property instead of acasts()method - Not using the
LogsActivitytrait on business models - Omitting return types on relationship methods
- Creating a model without a corresponding factory
- Putting business logic directly in the model — use Actions
References
- Laravel Eloquent Models
- Spatie Activity Log
- Related:
Enums/SKILL.md— enums are cast incasts() - Related:
Migrations/SKILL.md— migrations define the model's schema
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?