eloquent-patterns
Skill4 starsChanged 5 months agoMITView on GitHub
Laravel guidance to keep Eloquent models explicit, query shapes intentional, relationship loading visible, and production data access bounded.
In this repository75 other files it gives its agents.
- AGENTS.mdAGENTS.md
- templates/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- actions-and-servicesSkill
- ai-sdkSkill
- api-resources-and-paginationSkill
- api-surface-evolutionSkill
- architectureSkill
- blade-components-and-layoutsSkill
- brainstormingSkill
- code-review-requestsSkill
- complexity-guardrailsSkill
- config-env-storageSkill
- constants-and-configurationSkill
- controller-cleanupSkill
- controller-testsSkill
- custom-helpersSkill
- daily-workflowSkill
- database-transactionsSkill
- data-chunking-large-datasetsSkill
- debugging-promptsSkill
- dependencies-trim-packagesSkill
- documentation-best-practicesSkill
- e2e-playwrightSkill
- effective-contextSkill
- eloquent-relationshipsSkill
- exception-handling-and-loggingSkill
- executing-plansSkill
- extract-laravel-standardsSkill
- filesystem-uploadsSkill
- form-requestsSkill
- horizon-metrics-and-dashboardsSkill
- http-client-resilienceSkill
- integrate-whatsapp-baileys-laravelSkill
- interfaces-and-diSkill
- internationalization-and-translationSkill
- iterating-on-codeSkill
- laravel-11-12-app-guidelinesSkill
- laravel-database-optimizationSkill
- laravel-prompting-patternsSkill
- laravel-specialistSkill
- least-codeSkill
- livewire-developmentSkill
- memory-managementSkill
- migrations-and-factoriesSkill
- module-per-menuSkill
- nova-resource-patternsSkill
- performance-cachingSkill
- performance-eager-loadingSkill
- performance-select-columnsSkill
- php-attributesSkill
- policies-and-authorizationSkill
- ports-and-adaptersSkill
- prompt-structureSkill
- quality-checksSkill
- queues-and-jobsSkill
- rate-limitingSkill
- request-forgery-protectionSkill
- responsive-ui-testingSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 8 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Keep models explicit, query shape intentional, and relationship loading visible near the code that renders or returns data.
- Distinctive: line 45
Use accessors sparingly for simple derived values.
- Distinctive: line 51
Before rendering Blade reports, printable views, exports, or PDFs, explicitly load the relation graph.
- Distinctive: line 66
Do not add new relation dependencies inside templates without updating the load list and render tests.
- Very specific: line 70
Do not process unbounded production datasets with all() or broad get() calls.
- Distinctive: line 82
Keep bounded validation/display values in one source of truth.
- Distinctive: line 84
Prefer enums when supported.
- Distinctive: line 104
Use config files for deployment-level options and constants for small legacy/model-owned maps.
- Very specific: line 108
Use soft deletes with withTrashed() when historical records must remain readable after related reference data is removed from active use.
- Distinctive: line 110
Do not use this as a blanket rule for personal data or records subject to hard-delete compliance.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Eloquent Patterns
Keep models explicit, query shape intentional, and relationship loading visible near the code that renders or returns data.
Model Contracts
Models should declare mass-assignment boundaries, casts, and concrete relationship return types.
class Record extends Model
{
protected $fillable = [
'owner_id',
'number',
'total',
'issued_at',
'is_active',
];
protected function casts(): array
{
return [
'issued_at' => 'date',
'total' => 'decimal:2',
'is_active' => 'boolean',
'metadata' => 'array',
];
}
public function owner(): BelongsTo
{
return $this->belongsTo(User::class);
}
}Use accessors sparingly for simple derived values. Move heavy behavior into Actions or Services.
Relationship Loading
Prevent N+1 queries by eager loading the relations a surface needs.
Before rendering Blade reports, printable views, exports, or PDFs, explicitly load the relation graph.
public function show(Record $record): View
{
$record->load([
'owner',
'items.product',
'approvals.user',
]);
return view('records.show', ['record' => $record]);
}Do not add new relation dependencies inside templates without updating the load list and render tests.
Query Volume
Do not process unbounded production datasets with all() or broad get() calls.
Use:
paginate()for normal UI/API lists;- cursor pagination for large append-only lists;
chunkById()orlazyById()when updating rows during iteration;cursor()or lazy collections for streaming;- selected columns and indexed filters for high-volume paths.
Bounded Values
Keep bounded validation/display values in one source of truth.
Prefer enums when supported.
enum RecordStatus: string
{
case Draft = 'draft';
case Approved = 'approved';
case Cancelled = 'cancelled';
public function label(): string
{
return match ($this) {
self::Draft => 'Draft',
self::Approved => 'Approved',
self::Cancelled => 'Cancelled',
};
}
}Use config files for deployment-level options and constants for small legacy/model-owned maps.
Historical Data
Use soft deletes with withTrashed() when historical records must remain readable after related reference data is removed from active use.
Do not use this as a blanket rule for personal data or records subject to hard-delete compliance.
Snapshot attributes that must remain true for a historical document.
DocumentLine::create([
'reference_id' => $reference->id,
'reference_snapshot' => $reference->only(['code', 'name']),
]);Store only fields needed for historical correctness and avoid unnecessary sensitive data.
Context Efficiency
Layer: 3 (Implementation)
Load this skill only when models or queries need review. Do not load with unrelated skills. Keep changes minimal: explicit casts, eager-loaded relations, paginated queries, no unbounded all() or broad get() in production paths.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

