Why this lesson matters

Understand form requests and apply it in a small Laravel feature. Request handling becomes reliable when input is read deliberately and validation produces a controlled contract before business code runs.

How to reason about it

  • For Form Requests, the outcome to verify is: Keep validation close to the boundary where data enters the system.
  • In Form Requests, keep this failure controlled: Reading arbitrary request fields deep inside services makes validation inconsistent and lets malformed state travel too far.
  • Form Requests practice target: Create a request with valid and invalid payloads, then move its rules into a Form Request and compare controller clarity.

Practical walkthrough

In the Form Requests walkthrough: Keep validation close to the boundary where data enters the system.

app/Http/Requests/StoreUserRequest.phpphp
public function rules(): array
{
    return [
        'name' => ['required', 'string', 'max:120'],
        'email' => ['required', 'email'],
    ];
}

Practice it yourself

Practice

Form Requests exercise

Create a request with valid and invalid payloads, then move its rules into a Form Request and compare controller clarity.

  • Record the expected result before execution
  • Test one valid path and one lesson-specific failure path
  • Explain in two lines which boundary owns the decision

Summary