← ClaudeAtlas

form-requestslisted

Use Laravel Form Requests for non-trivial validation and authorization while keeping controllers thin and testable.
soden46/syarif-laravel-ai-skills · ★ 4 · API & Backend · score 78
Install: claude install-skill soden46/syarif-laravel-ai-skills
# Form Requests Use Form Requests for HTTP validation and request-bound authorization when rules are complex, reused, sensitive, or likely to grow. Inline controller validation is acceptable for tiny prototypes or legacy maintenance, but it is not the global standard for new or heavily edited workflows. ## Responsibilities A Form Request may: - authorize the HTTP operation; - normalize input in `prepareForValidation()`; - return validation rules; - use custom messages and attribute labels; - expose small helper methods for typed validated data. It should not: - perform database writes; - send external requests; - dispatch jobs; - contain long business workflows. ## Input Normalization Normalize human-formatted inputs before applying numeric/date/boolean rules. Keep locale assumptions explicit. ```php final class StoreRecordRequest extends FormRequest { protected function prepareForValidation(): void { $this->merge([ 'amount' => NumberInput::normalize($this->input('amount')), ]); } public function rules(): array { return [ 'amount' => ['required', 'numeric', 'min:0'], 'status' => ['required', Rule::enum(RecordStatus::class)], ]; } } ``` Shared parsers should be small helpers or value objects with unit tests. ## Authorization Use `authorize()` when the decision depends on request context or validated input. Use Policies when the decision depends on model state. ```php publ