Why this lesson matters

Understand validation basics 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 Validation Basics, the outcome to verify is: Keep validation close to the boundary where data enters the system.
  • In Validation Basics, keep this failure controlled: Reading arbitrary request fields deep inside services makes validation inconsistent and lets malformed state travel too far.
  • Validation Basics 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 Validation Basics 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

Validation Basics 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