controller-cleanup
Skill4 starsChanged 5 months agoMITView on GitHub
Keep Laravel controllers focused on HTTP orchestration by moving validation, authorization, and business workflows outward.
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-testsSkill
- custom-helpersSkill
- daily-workflowSkill
- database-transactionsSkill
- data-chunking-large-datasetsSkill
- debugging-promptsSkill
- dependencies-trim-packagesSkill
- documentation-best-practicesSkill
- e2e-playwrightSkill
- effective-contextSkill
- eloquent-patternsSkill
- 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
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 8 are distinctive, and 5 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.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Use this skill when controllers become difficult to understand, test, or maintain.
- Very specific: line 13
When a Laravel app has several menus/pages, also use module-per-menu: avoid one broad controller for the whole app, and split by menu, page …
- Very specific: line 22
call $this->authorize() or rely on middleware/Form Request authorization.
- Very specific: line 23
call a Form Request's validated() data.
- Distinctive: line 38
Keep coarse access requirements visible in routes or route groups.
- Very specific: line 50
Use Policies for model-state rules and Form Request authorize() for request-input-dependent authorization.
- Distinctive: line 54
Use controller actions for committed production endpoints that need middleware, sessions, tests, cache headers, or deployment route caching.
- Distinctive: line 58
Place static or specific routes before broad resource routes when URI patterns could collide.
- Very specific: line 67
Verify collision-prone route changes with php artisan route:list or a feature test.
- Distinctive: line 87
Do not extract one-line code merely to create more layers.
- Distinctive: line 88
Do not require Repository Pattern by default.
- Distinctive: line 89
Keep framework-specific HTTP concerns in controllers.
- Distinctive: line 90
Keep reusable business operations outside controllers.
≈ “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
Controller Cleanup
Use this skill when controllers become difficult to understand, test, or maintain.
When a Laravel app has several menus/pages, also use module-per-menu: avoid one broad controller for the whole app, and split by menu, page group, or resource boundary.
Controllers should stay thin and focused on HTTP orchestration. They should not contain long business workflows, provider payload construction, repeated query logic, or file-processing loops.
Responsibilities
A controller may:
- receive route-bound models and requests;
- call
$this->authorize()or rely on middleware/Form Request authorization; - call a Form Request's
validated()data; - invoke an Action or Service;
- return redirects, views, JSON resources, streams, or downloads;
- attach session flash messages.
A controller should not:
- build external provider payloads inline;
- contain multi-step write workflows without a transaction boundary;
- duplicate validation rules;
- hide authorization inside unrelated branches;
- contain heavy report/query logic that is reused elsewhere.
Route Boundaries
Keep coarse access requirements visible in routes or route groups.
Route::middleware(['auth', 'verified'])->group(function () {
Route::resource('records', RecordController::class)
->middlewareFor('index', 'can:viewAny,' . Record::class)
->middlewareFor(['create', 'store'], 'can:create,' . Record::class)
->middlewareFor(['edit', 'update'], 'can:update,record')
->middlewareFor('destroy', 'can:delete,record');
});Use Policies for model-state rules and Form Request authorize() for request-input-dependent authorization.
Route Order And Cache Safety
Use controller actions for committed production endpoints that need middleware, sessions, tests, cache headers, or deployment route caching.
Route closures are acceptable for static views, simple redirects, prototypes, and temporary debugging.
Place static or specific routes before broad resource routes when URI patterns could collide.
Route::get('records/export', ExportRecordsController::class)
->name('records.export');
Route::resource('records', RecordController::class);Verify collision-prone route changes with php artisan route:list or a feature test.
Generic Store Pattern
final class RecordController
{
public function store(StoreRecordRequest $request, CreateRecord $create): RedirectResponse
{
$record = $create->handle($request->user(), $request->validated());
return redirect()
->route('records.show', $record)
->with('status', 'Record created.');
}
}Guardrails
- Do not extract one-line code merely to create more layers.
- Do not require Repository Pattern by default.
- Keep framework-specific HTTP concerns in controllers.
- Keep reusable business operations outside controllers.
Context Efficiency
Layer: 3 (Implementation)
Load this skill only when controllers need cleanup. Do not load with unrelated skills. Keep the diff minimal: inline validation only when rules are tiny, otherwise Form Request; one Action per use case; no repository by default.
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.

