resource-first-controllers
Skill1 starsChanged 34 days agoMITView on GitHub
Enforces resource-first controller design in Laravel. Apply whenever creating, modifying, or reviewing controllers, defining routes, or planning new features that involve HTTP endpoints.
In this repository7 other files it gives its agents.
- guidelines/agents.mdAGENTS.md
- code-reviewSkill
- eurekaSkill
- plansSkill
- security-reviewSkill
- sequential-implementation-orchestrationSkill
- tddSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Every controller is a resource until proven otherwise.
- Distinctive: line 47
Only when ALL of these are true:
- Distinctive: line 55
When the user asks for any controller or endpoint:
- Distinctive: line 61
If proposing an invokable controller, explicitly justify why none of the 7 methods fit.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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
Resource-First Controller Design
Core Principle
Every controller is a resource until proven otherwise. Before writing any controller, ask: "Can this be modeled as a resource?"
Decision Flow
- Identify the noun (the thing being acted upon). If you can name a resource, use a resource controller.
- Map actions to the 7 standard methods:
index→ listcreate→ show creation formstore→ persist newshow→ display oneedit→ show edit formupdate→ persist changesdestroy→ delete
- Partial resources are encouraged (1–7 methods). Use
Route::resource(...)->only([...])or->except([...]). - Invokable controllers are a LAST RESORT — only when the action genuinely cannot map to any standard method (e.g.,
GenerateMonthlyReportController,ExchangeOAuthTokenController).
Hard Rules (do not violate)
- ❌ No custom methods on resource controllers. A controller either has only resource methods, or it is invokable.
- ❌ No mixed controllers. If you feel tempted to add
publish(),archive(),approve()→ that's a new resource (PublishedPostController@store,PostArchiveController@store, etc.). - ❌ No grab-bag controllers (e.g.,
UserControllerwithprofile(),settings(),avatar()). Split intoUserProfileController,UserSettingsController,UserAvatarController. - ✅ Nested resources are preferred over custom methods:
Route::resource('posts.comments', ...). - ✅ State changes are resources too: subscribing =
SubscriptionController@store, unsubscribing =SubscriptionController@destroy.
Reframing Patterns (use these)
| Tempting custom method | Resource-first refactor |
PostController@publish | PublishedPostController@store |
UserController@activate | ActiveUserController@store |
OrderController@cancel | OrderController@destroy or CancelledOrderController@store |
AuthController@login | SessionController@store |
AuthController@logout | SessionController@destroy |
UserController@search | UserController@index (filter via query params) |
When Invokable Is Acceptable
Only when ALL of these are true:
- The action does not create/read/update/delete an identifiable resource.
- It cannot be reframed as a state-resource without contortion.
- Examples: webhooks (
StripeWebhookController), one-off jobs (RecalculateRankingsController), pure RPC integrations.
Required Workflow For The Assistant
When the user asks for any controller or endpoint:
- State the resource you've identified.
- List which of the 7 methods apply, and which are excluded.
- Generate the artisan command:
php artisan make:controller {Name}Controller --resource --model={Model}. - Generate the route using
Route::resource(...)(with->only(...)if partial). - If proposing an invokable controller, explicitly justify why none of the 7 methods fit.
Self-Check Before Returning Code
- Does this controller have ONLY resource methods, OR is it
__invoke? - Did I avoid adding
publish/approve/toggle/etc.as a method? - If I used invokable, did I justify why no resource framing works?
- Are routes declared with
Route::resource/Route::apiResource(not individualRoute::get/post)?
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.

