Challenge 2: Create a FormRequest — Possible Solution ==================================================================== # php artisan make:request UpdateBookRequest # FormRequest created successfully. // app/Http/Requests/UpdateBookRequest.php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class UpdateBookRequest extends FormRequest { public function authorize(): bool { return true; } public function rules(): array { return [ 'title' => 'required|string|max:255', 'price' => 'required|numeric|min:0', ]; } } // app/Http/Controllers/BookController.php — BEFORE (inline validation) public function update(Request $request, Book $book) { $validated = $request->validate([ 'title' => 'required|string|max:255', 'price' => 'required|numeric|min:0', ]); $book->update($validated); return redirect()->route('books.show', $book); } // app/Http/Controllers/BookController.php — AFTER (using the FormRequest) use App\Http\Requests\UpdateBookRequest; public function update(UpdateBookRequest $request, Book $book) { $book->update($request->validated()); return redirect()->route('books.show', $book); } WHY THIS WORKS -------------- - Swapping the parameter type from Illuminate\Http\Request to App\Http\Requests\UpdateBookRequest is the entire change needed at the controller level — Laravel's service container resolves the type hint, automatically runs UpdateBookRequest's rules() against the incoming request BEFORE the update() method body executes, and only calls the method at all if validation passes. - Route model binding (Chapter 3) and FormRequest validation compose cleanly together in the same method signature — Book $book is resolved from the route parameter, UpdateBookRequest $request is resolved and validated independently, and both happen before a single line of the method body runs. - Moving rules() into its own class means the same validation rules could be reused elsewhere (a different route hitting the same update logic, or a test asserting against UpdateBookRequest::rules() directly) without duplicating the rule strings — the same "don't repeat this logic" motivation behind extracting a dedicated class rather than leaving validation inline forever.