Enforce request validation style rules
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: project-request-validation-style
|
||||
description: "Always apply in this project when changing Laravel controllers or FormRequest classes. Enforces dedicated FormRequest usage for controller validation, validated-array access via Arr::get(), and forbids custom single-field getter methods or request helper extraction like boolean()/integer()/string() for app input handling."
|
||||
---
|
||||
|
||||
# Project Request Validation Style
|
||||
|
||||
## When to Apply
|
||||
|
||||
Activate this skill whenever work in this project changes:
|
||||
|
||||
- Laravel controllers
|
||||
- Laravel FormRequest classes
|
||||
- Validation flow between controllers and requests
|
||||
|
||||
## Rules
|
||||
|
||||
- Do not add inline controller validation with `$request->validate(...)` when the endpoint has request-specific validation needs.
|
||||
- Prefer dedicated `FormRequest` classes and use `$validated = $request->validated();` in controllers.
|
||||
- When reading validated arrays, use `Arr::get($validated, 'key')` instead of direct array access.
|
||||
- Do not use request helper extraction like `$request->boolean()`, `$request->integer()`, `$request->string()`, or similar helpers for application input handling.
|
||||
- Do not add custom FormRequest getter helpers such as `points()`, `branchName()`, `ticketAttributes()`, or similar single-purpose accessors.
|
||||
- Build controller payloads from the validated array directly with `Arr::get(...)`.
|
||||
|
||||
## Notes
|
||||
|
||||
- `Arr::get(...)` already returns `null` by default, so do not wrap it in redundant existence checks when `null` is acceptable.
|
||||
- Keep validation logic in the FormRequest and payload shaping in the controller or dedicated action.
|
||||
Reference in New Issue
Block a user